Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8175 > unrolled thread
| Started by | Saul Spatz <saul.spatz@gmail.com> |
|---|---|
| First post | 2011-06-21 20:22 -0700 |
| Last post | 2011-06-22 08:03 -0500 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
Re: Tkinter/scrollbar/canvas question Saul Spatz <saul.spatz@gmail.com> - 2011-06-21 20:22 -0700
Re: Tkinter/scrollbar/canvas question agb <andrei.bogos@a.gmail.address.com> - 2011-06-22 08:03 -0500
| From | Saul Spatz <saul.spatz@gmail.com> |
|---|---|
| Date | 2011-06-21 20:22 -0700 |
| Subject | Re: Tkinter/scrollbar/canvas question |
| Message-ID | <56de203d-0ef4-4c19-8b5b-074c7d8e2ccc@glegroupsg2000goo.googlegroups.com> |
It works if you change it like so:
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(self)
cframe.grid(row=1, sticky=N+S+E+W)
canv = Canvas(cframe)
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)
id = 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)
aframe.update_idletasks()
canv["scrollregion"]=canv.bbox(ALL)
root = Tk()
m=ShowList(root)
root.mainloop()
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.)
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.
Saul
[toc] | [next] | [standalone]
| From | agb <andrei.bogos@a.gmail.address.com> |
|---|---|
| Date | 2011-06-22 08:03 -0500 |
| Message-ID | <4e01da25_1@news.mccarragher.com> |
| In reply to | #8175 |
Saul Spatz wrote: <very helpful stuff snipped> > > 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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web