By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

treeview / pygtk problem

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Thu, 2003-07-10 at 11:53, Andre Lerche wrote:
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)

----^
That's your problem right there: text= expects a sequence from 0 to n.
So try:

col1 = g.TreeViewColumn ("col 1", renderer, text=0)
col2 = g.TreeViewColumn ("col 2", renderer, text=1)

That should solve your problem!

-Tim
ti*@gerla.net
Jul 18 '05 #2

P: n/a
Hi Tim,

Tim Gerla <ti*@gerla.net> wrote in message news:<ma**********************************@python. org>...
On Thu, 2003-07-10 at 11:53, Andre Lerche wrote:
Hi list, [...] renderer = g.CellRendererText ()
col1 = g.TreeViewColumn ("col 1", renderer, text=1)
col2 = g.TreeViewColumn ("col 2", renderer, text=1)

----^
That's your problem right there: text= expects a sequence from 0 to n.
So try:

col1 = g.TreeViewColumn ("col 1", renderer, text=0)
col2 = g.TreeViewColumn ("col 2", renderer, text=1)

That should solve your problem!

-Tim
ti*@gerla.net


Yes, this has solved my problem, I was really to dumb.

Thanks,

Andre
Jul 18 '05 #3

P: n/a
In article <ea*************************@posting.google.com> , Andre Lerche
wrote:
col1 = g.TreeViewColumn ("col 1", renderer, text=0)
col2 = g.TreeViewColumn ("col 2", renderer, text=1)

That should solve your problem!

-Tim
ti*@gerla.net


Yes, this has solved my problem, I was really to dumb.


Hardly; this API is quite obscure.

Dave Cook
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.