tkinter - change size of Frame even if there widget python -


hi there way change width , height of widget if there's widget? have code this

  form = tk()   form.geometry("500x500")    def click():       global frame       frame.config(height = 0 ,width =  0)     frame = labelframe(form , text = "vaaja")   frame.place(x = 20 , y = 30)    label(frame, text ="1").grid(row = 0,column = 0 )    label(frame, text =  "2").grid(row = 1 ,column = 0 )     button(form , text="click", command = click).place(x = 200 ,  y = 200)     form.mainloop() 

and when click button size of frame same ( i'cant use grid_forget() labels , change size of frame)

because using place, have 2 solutions: can use place set width , height zero, or can turn geometry propagation off.

using place set width , height

place allows define width , height of placed widget, in click function can this:

def click():     frame.place_configure(width=0, height=0) 

turning geometry propagation off

a frame resized fit contents called "geometry propagation". if turn off, can control size of frame width , height options of frame itself. it's better let tkinter decide size you, there's need have explicit size, why it's possible turn geometry propagation off.

since using grid manage widgets internal frame, need use grid_propagate(false) turn geometry propagation off frame:

frame.grid_propagate(false) 

by doing so, you're responsible setting initial width , height of widget, though leave propagation on initial size, turn off button click in order work around issue.

there's interesting bug (or feature...) in if set width , height zero, tkinter won't redraw window. @ least, doesn't on mac. don't recall workaround because never, ever need set widget 0 size, setting 1x1 pixel makes invisible.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -