Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

python - Why is this PyGTK menu empty?

I am working on a PyGTK application with a Gtk.Toolbar. One of the items in taht toolbar is a Gtk.MenuToolButton. However, clicking on the arrow once the program runs results in an empty menu (a tiny white sliver). Here is the code that sets up the menu:

                self.compileMenu = Gtk.Menu()
                self.defaultCompileOption = Gtk.MenuItem(label = "Compile with defaults")
                self.configCompileOption = Gtk.MenuItem(label = "Change compile options...")
                self.compileWithFiles = Gtk.MenuItem(label = "Bundle files...")
                
                self.compileMenu.append(self.defaultCompileOption)
                self.compileMenu.append(self.configCompileOption)
                self.compileMenu.append(self.compileWithFiles)
                
                self.compileButton = Gtk.MenuToolButton(icon_name = "x-package-repository", label = "Compile...", menu = self.compileMenu)

There is also a call to self.toolbar.add at the bottom, to add the MenuToolButton to the toolbar.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Found the issue! Turns out that for some reason you need to call, in my case, compileMenu.show_all() to make it realize that you added things to it.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...