Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #8178 > unrolled thread
| Started by | Saul Spatz <saul.spatz@gmail.com> |
|---|---|
| First post | 2011-06-21 20:50 -0700 |
| Last post | 2011-06-22 15:30 +1000 |
| 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:50 -0700
Re: Tkinter/scrollbar/canvas question Chris Angelico <rosuav@gmail.com> - 2011-06-22 15:30 +1000
| From | Saul Spatz <saul.spatz@gmail.com> |
|---|---|
| Date | 2011-06-21 20:50 -0700 |
| Subject | Re: Tkinter/scrollbar/canvas question |
| Message-ID | <0eb0e433-56bb-4eb9-bfdc-e13608ab446e@glegroupsg2000goo.googlegroups.com> |
This is the third time I've tried to post this reply. If you see multiple answers from me, that's why.
Your script will work 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 call update_idletasks to force the canvas to be mapped to the screen before you compute the bounding box. Until it's mapped, the bounding box is (0,0,1,1), and of course you need to put the widgets on before you compute the bounding box. You can call update_idletasks through any widget.
That said, I wonder if it wouldn't be better to put canvas objects directly on the canvas, instead of putting widgets in a frame. The way you'r doing it, you can't give the widgets tags, and tags are what give the canvas its power.
Saul
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-06-22 15:30 +1000 |
| Message-ID | <mailman.271.1308720622.1164.python-list@python.org> |
| In reply to | #8178 |
On Wed, Jun 22, 2011 at 1:50 PM, Saul Spatz <saul.spatz@gmail.com> wrote: > This is the third time I've tried to post this reply. If you see multiple answers from me, that's why. > All three came through on the mailing list, but out of order - this one came in second. Chris Angelico
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web