python - expand within notebook does not work as expected -


here attempts widget stay in center of screen window re-sizes. mean normal behavior of grid sticky='ew' frame packed expand , fill='x'. here demo code show mean:

from tkinter import frame,button,label ttk import notebook  root = frame() root.pack(expand=true,fill='both') nb = notebook(root)  btn_f = frame(nb) button(btn_f, text="button packed").pack(pady=100,padx=100) # btn_f.pack(expand=true,fill='both') #makes no difference if removed  lbl_f = frame(nb) label(lbl_f, text="this label in grid").grid(pady=100,sticky='ew') # lbl_f.grid() #makes no difference if removed  nb.add(btn_f, text="button") nb.add(lbl_f, text="label")  nb.pack(expand=true,fill='x')  root.mainloop() 

my suspicion has discovered commenting out pack , expand. add method in notebook run it's own layout manager handle how frame placed in it? i'm asking how achieve affect of centering grid, demonstrated in first tab using pack?

this code makes behave same packed button.

lbl_f = frame(nb) label(lbl_f, text="this label in grid").grid(pady=100,sticky='ew') lbl_f.grid() lbl_f.rowconfigure('all', weight=1) lbl_f.columnconfigure('all', weight=1) 

as can see, row/columnfigure applied frame element.


p.s. suggest modify code slightly. makes easier down road if change widgets such (for example):

button(btn_f, text="button packed").pack(pady=100,padx=100)  

to

packedbutton = button(btn_f, text="button packed") packedbutton.pack(pady=100,padx=100)  

this way, can refer button (or whatever widget) later on. cannot create/pack(or grid) widget on same line though; must down separately shown here.

another positive change use classes. there lot of examples on so, if code in question quick sample more power you. luck!


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -