Hi!

I have been studying the pygtk tutorial (or any gtk for that matter)
for a week now, so bear with me if I don't have everything straight.

Basically I want to have a menu in my program. So I created a MenuBar,
and appended a MenuItem to it. Now when I click this MenuItem I don't
want a menu to pop up like one normally would, instead I want a
ListStore to pop up. Is this possible? I tried doing it the way I
thought might work but I had no luck.

Below is an example piece of code to work the way I had in mind. When
I run it it complains:
example.py:26: GtkWarning: gtk_menu_attach_to_widget: assertion
`GTK_IS_MENU (menu)' failed
 menu_item.set_submenu(tree_view)

This makes sense but I was wondering if there is some way around this.

Thanks for any help!

This is what my example code looks like that generated this warning:

#/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk

class Example:
        def __init__(self):
                self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
                menu_item = gtk.MenuItem("hello")
                menu_bar = gtk.MenuBar()
                menu_bar.append(menu_item)
                
                list_store = gtk.ListStore(str)
                for i in range(4):
                        list_store.append(["list store item %i" % i])
        
                tree_view = gtk.TreeView(list_store)
                col = gtk.TreeViewColumn("Column")
                tree_view.append_column(col)
                cell = gtk.CellRendererText()
                col.pack_start(cell, True)
                col.add_attribute(cell, 'text', 0)
                
                menu = gtk.Menu()
                
                self.window.add(menu_bar)
                menu_item.set_submenu(tree_view)

        def main(self):
                self.window.show_all()
                gtk.main()
                
Example().main()
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to