Tkinter/scrollbar/canvas question

2011-06-21 Thread agb
Dear Pythonistas,

I've been trying to write a script that results in a set of widgets in a
scrollable widget. Since tkinter is "the" gui for Python (and about the
only one that I can be sure will not require additional software
installation), I went that route, and wrote the following:

from tkinter import *
class ShowList(Frame):
def __init__(self, root):
Frame.__init__(self, root)
self.grid()
self.draw_widgets()
def draw_widgets(self):
cframe = Frame()
cframe.grid(row=1, sticky=N+S+E+W)
canv = Canvas(cframe)
canv["scrollregion"]=canv.bbox(ALL)
canv.grid(row=0, column=0, sticky=N+S+E+W)
vscroll = Scrollbar(cframe, orient=VERTICAL, command=canv.yview)
hscroll = Scrollbar(cframe, orient=HORIZONTAL, 
command=canv.xview)
vscroll.grid(row=0, column=1, sticky=N+S)
hscroll.grid(row=1, column=0, sticky=E+W)
canv["xscrollcommand"] = hscroll.set
canv["yscrollcommand"] = vscroll.set
aframe = Frame(canv)
canv.create_window(0,0,window=aframe, anchor=N+W)
for i in range(0,100):
Label(aframe, text=str(i), anchor=N+W).grid(row=i, 
column=0)

root  = Tk()
m=ShowList(root)
root.mainloop()


...which is great in that it does display the list of items (in this case, a
bunch of Labels) but not so great in the fact that the vertical scrollbar's
scroll thumb is the list of the entire scroll trough, making skip down/up a
screenful impossible. Both the horizontal scrollbar and the vertical
scrollbar will scroll until the list is off the screen (not the desired
behavior). 

Initially, I thought the canv["scrollregion"] = canv.bbox(ALL) would take
care of the off-screen scrolling by making the scrollable region no larger
than it needs to be. Reading many examples of Python+tkinter code, intended
to demonstrate the way to code scrollbars and canvases, didn't enlighten me
enough to figure out the bug(s) in my code. Any suggestions as to what I
did wrong?

Many thanks in advance,

--agb

--
http://gall.mine.nu
free to get comics,free chat-1,dc++ (dcplusplus),
mute webcache,group update program,torrent,atomic time server,tool to find your 
ip
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter/scrollbar/canvas question

2011-06-22 Thread agb
Saul Spatz wrote:


> 
> You need to do the update_idletasks to force the canvas to be mapped
> before you figure out the bounding box.  Until the canvas is mapped to the
> screen, the bounding box is (0,0,1,1) so there no scrolling possible. 
> (You can call update_ideltasks through any widget.)

Many thanks--this fixed the issue.

> That said, I wonder why you're putting widgets in the frame instead of
> putting objects directly on the canvas.  The way you're doing it you can't
> use tags, which are what really give the canvas its power.

The power of canvas is not really what I'm after. What I would like is a
list of checkboxes (and, in a few other frames, several buttons); if a
scrollable frame were available in tkinter, I'd use that. While canvas is
powerful, its power is not needed for my purposes.

> 
> Saul

--
http://gall.mine.nu
free to get comics,free chat-1,dc++ (dcplusplus),
mute webcache,group update program,torrent,atomic time server,tool to find your 
ip
-- 
http://mail.python.org/mailman/listinfo/python-list