treeview / pygtk problem

Andre Lerche andre.lerche at update.com
Thu Jul 10 14:53:24 EDT 2003


Hi list,

I am quite new to Python and try to learn Python with a small pygtk
program. I am facing a problem which I am unable to solve for myself.
I think I have read the documentation and some samples, but however
I cannot find my mistake, so hopefully someone can help me with a
short hint. This is a small sample application which demonstrates
my problem:

import gtk as g
import gobject

window = g.Window ()
window.connect ('delete_event', g.mainquit)
scrolledwin = g.ScrolledWindow ()
renderer = g.CellRendererText ()
col1 = g.TreeViewColumn ("col 1", renderer, text=1)
col2 = g.TreeViewColumn ("col 2", renderer, text=1)
model = g.ListStore (gobject.TYPE_STRING, gobject.TYPE_STRING)
view = g.TreeView ()
view.set_model (model)
view.set_headers_visible (1)
view.append_column(col1)
view.append_column(col2)

scrolledwin.add (view)
window.add (scrolledwin)
window.show_all ()

iter = model.append ()
# -- Problem -- #
model.set (iter, 0, "foo", 1, "bar")
# ------------- #
g.mainloop ()

I thought, with the marked model.set... I can set the first row in my
treeview to col1 = foo and col2 = bar. But, if I execute the script
the 2 columns are set to bar.

Where is my mistake? I am using Python 2.2.2 on RedHat 9.

Thanks,

Andre




More information about the Python-list mailing list