Tkinter scrollbar question
Laura Creighton
lac at strakt.com
Fri Nov 9 11:08:45 EST 2001
I can't seem to get my scrollbar to work.
I have a class Table:
These lines are in its __init__
self.yscrollbar = Tkinter.Scrollbar(self, orient='vertical')
self.yscrollbar.pack(side='right', fill='y')
self.yscrollbar.config(command=self.yview)
This is the method yview:
def yview(self, delta):
if int(delta) == 1:
self.move_everybody_up()
if int(delta) == -1:
self.move_everybody_down()
move_everybody_up() and move_everybody_down() work as expected.
Right now, you can click on the scroll bar and the table scrolls by one
row, exactly as ordered. All the work gets done in a method called
loadTable. The problem happened when I added these lines:
print 'start %d, size %d, total %d' % (
self.vr_start, self.vr_size, self.totalLineCount)
low = float(self.vr_start)/self.totalLineCount
high = float(self.vr_start + self.vr_size)/self.totalLineCount
print 'low is: %f, high is: %f' % (low, high)
sb=self.yscrollbar.get()
print 'sb is:' , sb
self.yscrollbar.set(low, high) # this definitely is the problem
lac at ratthing-b246:$ python Table.py
start 4, size 6, total 12
low is: 0.333333, high is: 0.833333
sb is: (0.0, 0.0, 0.0, 0.0)
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/local/lib/python2.1/lib-tk/Tkinter.py", line 1289, in __call__
return apply(self.func, args)
TypeError: yview() takes exactly 2 arguments (4 given)
----------------------------
What am I doing wrong? Where are the _4_ arguments coming from?
Changing the name to yyview did not help matters. A google search
lead me to:
http://groups.google.com/groups?q=Tkinter+scrollbar+set++group:comp.lang.python&hl=en&rnum=4&selm=slrn9k6ldn.nn.matt%40happy-hour.mondoinfo.com
That talks about backwards compatibility of the scrollbar's get
method returning a tuple of 4, not 2, just after you create it.
So I added lines to check that, and yes, indeed, I get a tuple
of 4 (as you just saw). Is this a coincidence?
Thanks very much,
Laura Creighton
More information about the Python-list
mailing list