[Tkinter-discuss] simple scrollbar... not so simple

Sorin Schwimmer sxn02 at yahoo.com
Fri Nov 26 07:30:26 CET 2010


Mick, you saved me!

My test code looks now like this (I hope HTML tags are honoured):

from Tkinter import *

r=Tk()
tx=Text(r,width=6) # hosts the frames and allows scrollbar
sb=Scrollbar(r,command=tx.yview)
tx['yscrollcommand']=sb.set
f=Frame(tx) # hosts my stuff
<b>tx.window_create(END,window=f)</b>
tx.grid()
sb.grid(row=0,column=1,sticky=NS)
for i in range(50):
  Label(f,text=('line #%d' % i)).grid()
	
r.mainloop()

Instead of "grid" for the frame, I used a "window_create", as per your example, and ta-da! it works.

The Text width is an arbitrary 6, I don't know how to make it as large as the frame, but not larger, and I also don't know how to show the scroll bar only when needed. But I can live with these two minor shortcomings, and the real application behaves fine.

Thank you
SxN




More information about the Tkinter-discuss mailing list