Layout management in tkinter.

Martin Franklin martin.franklin at westgeo.com
Thu Feb 14 09:55:45 EST 2002


Eric Brunel wrote:

> Hi Lukasz,
> 
> Lukasz Pawelczyk wrote:
>> Hello,
>> 
>> I try to change the geometry manager pack into grid in the code
>> and I have problem.
>> Why it does not work?
>> 
>> prz1=Button(main,text="Otworz",cursor="question_arrow",command=otworz)
>> prz1.grid(row=0)
>> 
>> prz2=Button(main,text="Zachowaj",cursor="dot",command=zachowaj)
>> prz2.grid(row=0,column=1)
>> 
>> prz3=Button(main,text="Zamknij",cursor="pirate",command=wyjscie)
>> prz3.grid(row=0,column=2)
>> 
>> plik=ScrolledText(main,background="grey")
>> plik.grid(row=1,column=0,columnspan=3)                - there the code
>> stop
> 
> You didn't mention where you got the ScrolledText widget, but apparently
> you did a "from ScrolledText import ScrolledText", isn't it? If it is, I
> do have the same problem: apparently, the creation or gridding of the
> ScrolledText tries to pack something in the "main" widget, which results
> in program hanging.
> 
> I would advise not to use the ScrolledText widget from the ScrolledText
> module since it is obviously not so well designed... Either use the Text
> and Scrollbar widgets from Tkinter (you'll have to bind them to each other
> explicitely, but it's quite easy), or use the ScrolledText widget
> from PMW (Python MegaWidgets) that you'll find at:
> http://pmw.sourceforge.net/
> You'll also find in PMW a great deal of other very useful widgets.
> 
> HTH
>  - eric -
> 

I have noticed Tkinter hanging when I (by mistake) pack and grid widgets 
into the same parent! You don't seem to be doing this however the 
ScrolledText widget uses a frame widget 'under the covers and this uses 
pack to 'pack' the scrollbar.  the grid() call to the scrolledtext widget 
is passed to this frame widget therefore without knowing it you are trying 
to pack and grid widgets into the same parent!.....


This is what I came up with :-

from Tkinter import *
from ScrolledText import ScrolledText


main=Tk()

f=Frame(main)
f.pack(fill='both', expand='yes')

prz1=Button(f,text="Otwórz",cursor="question_arrow",command=None)
prz1.pack(side='left')

prz2=Button(f,text="Zachowaj",cursor="dot",command=None)
prz2.pack(side='left', expand='yes')

prz3=Button(f,text="Zamknij",cursor="pirate",command=None)
prz3.pack(side='right')

plik=ScrolledText(main,background="grey")
plik.pack(fill='both', expand='yes')           

main.mainloop()


HTH
Martin

















More information about the Python-list mailing list