[Tkinter-discuss] horizontal scrollbar in frame with text widget

Michael Lange klappnase at web.de
Sat Jan 1 22:53:04 CET 2011


Hi,

Thus spoketh <spooky.ln at tbs-software.com> 
unto us on Sat, 1 Jan 2011 20:56:57 +0100:

> Hi all,
> I’m new on the list. Now moving from GTK to Tkinter.

Then welcome aboard :)

> I have question about packing in frame.
> 
> Example:
> 
> frame2 = Frame(self)
> hScrollbar = ttk.Scrollbar(frame2, orient=HORIZONTAL)
> self.text = Text(frame2,
>                         font='Courier 9',
>                         undo=True,
>                         background='white',
>                         wrap=NONE)
> self.text.pack(fill=BOTH, expand=1)
> hScrollbar.pack(side=BOTTOM, fill=X)
> frame2.pack(side=LEFT, fill=BOTH, expand=1)
> 
> in this little example i have defined hScrollbar.
> all working fine until i resize main window when frame2 is.
> if i resize window under 24lines in Text is visible scrollbar dissapear.
> 
> is this wrong packing ? thanks.

I think if you change the packing order, like:

    hScrollbar.pack(side=BOTTOM, fill=X)
    self.text.pack(fill=BOTH, expand=1)

the scrollbar should remain visible when the window size decreases.
Another, less elegant, solution might be to decrease the Text widget's
size through its width and height options, however then you will have to
make sure somewhere else in your code that you don't end up with a tiny
window.

I hope this helps

Michael

P.S.
A happy new year to all of you!

.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Respect is a rational process
		-- McCoy, "The Galileo Seven", stardate 2822.3


More information about the Tkinter-discuss mailing list