LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Python: Placing a gtk.Entry() into a Toolbar (http://www.linuxquestions.org/questions/programming-9/python-placing-a-gtk-entry-into-a-toolbar-887069/)

MetaMan 06-18-2011 11:59 AM

Python: Placing a gtk.Entry() into a Toolbar
 
I've searched the web for quite a while and cannot seem to find a way to add a gtk.Entry() to a toolbar via toolbar.insert().

I currently have this:
Code:

...
self.toolbar = gtk.Toolbar()
self.text = gtk.Entry()
self.toolbar.insert(self.text, 0)
...

Which in turn spits out "Gtk.Toolbar.insert() argument 1 must be gtk.ToolItem, not gtk.Entry"

How would I do this correctly?

Thanks! :D

MTK358 06-18-2011 02:31 PM

I'm not a GTK+ expert (I use Qt), but I found this in the documentation:

ToolItem is a subclass of Bin which is a subclass of Container. Container has an add() method to add a child. So I would try this:

Code:

item = gtk.ToolItem()
item.add(self.text)
self.toolbar.insert(item, 0)

Note that it is not necessary to prepend "self." to all variables which hold a widget, you only need it for those that you will reference later from other methods.

MetaMan 06-18-2011 04:34 PM

Thanks! I agree that all the selfs don't make much sense as is, but there's a lot of code I cut out to get to the point.

Again, Thanks! :D


All times are GMT -5. The time now is 07:59 PM.