Programatically Add New Menu Items To Menu Item Pygobject?
I had this set up in wxPython, but now I'm rewriting it for GTK3/PyGObject, and I'm kind of lost here. Basically, my code scans through a directory, and adds the names of files to
Solution 1:
What you're looking for is append()
. Also, the common hierarchy is:
- GtkMenuBar
- GtkMenuItem
- GtkMenu
- GtkMenuItem
- GtkImageMenuItem
- GtkCheckMenuItem
- GtkRadioMenuItem
- GtkSeparatorMenuItem
- GtkMenu
- GtkMenuItem
You can find a full example here:
https://gist.github.com/carlos-jenkins/8851942
The relevant part of the code is:
content = [
'Path to file 1',
'Path to file 2',
'Path to file 3',
'Path to file 4',
]
# Create menu
menu = Gtk.MenuItem(label='My Menu {}'.format(num))
menu.set_submenu(Gtk.Menu())
for p in content:
menu.get_submenu().append(Gtk.MenuItem(label=p))
self.menubar.append(menu)
menu.show_all()
Post a Comment for "Programatically Add New Menu Items To Menu Item Pygobject?"