[pygtk] Having problems using gtk.CellRendererCombo
Kim Novak
kim at trdlnk.com
Tue Nov 7 03:50:52 WST 2006
The CellRendererCombo needs to be editable. The drop-down will only
appear when you click on the cell.
cellcombo.set_property("editable", True)
John Wood wrote:
> Hello,
>
> I'm having a hard time using a gtk.CellRendererCombo in my treeview
> widget. The problem is that the combobox widget won't show. I've read
> the pygtk reference a number times and the I get no errors executing
> my code. I've created a small sample program which illustrates my
> problem.
>
> Any help is much appreciated, if someone can point me to a pygtk
> program that uses gtk.CellRendererCombo that would be great.
>
> John
>
> #!/usr/bin/env python
> import sys
>
> try:
> import pygtk
> pygtk.require("2.6")
> except:
> pass
>
> try:
> import gtk
> except:
> sys.exit(1)
>
> class CellRendererExample:
> """ Main class of the application. """
>
> def __init__(self):
> # Create window and connect its destroy signal.
> window = gtk.Window()
> window.connect("destroy", gtk.main_quit)
>
> # Create and add a treeview widget to the window.
> self.treeview = gtk.TreeView()
> window.add(self.treeview)
>
> # Create a text column
> column0 = gtk.TreeViewColumn("Text",
> gtk.CellRendererText(),
> text=0)
>
> # Create a combobox column
> cellcombo = gtk.CellRendererCombo()
>
> model = gtk.ListStore(str)
>
> for k in range(1,10):
> model.append(["item_%d" % k])
>
> cellcombo.set_property("model", model)
>
> column1 = gtk.TreeViewColumn("Combobox", cellcombo)
>
> column1.add_attribute(cellcombo, "text-column", 1)
>
> self.treeview.append_column(column0)
> self.treeview.append_column(column1)
>
> # Create liststore.
> liststore = gtk.ListStore(str, int)
>
> # Append a couple of rows.
> liststore.append(["Some text", 0])
> liststore.append(["More text", 1])
>
> # Set model.
> self.treeview.set_model(liststore)
>
> window.show_all()
>
> def main(self):
> gtk.main()
>
> if __name__ == "__main__":
> cre = CellRendererExample()
> cre.main()
> _______________________________________________
> pygtk mailing list pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
More information about the pygtk
mailing list