python - How to make Tkinter button to not disappear when option in OptionMenu is selected? -


i have code:

def type():     variable=var.get()     if variable=="text caps":         import caps_main.py   tkinter import * t = tk() t.geometry("500x300") p = photoimage(file="c:\users\indrek\downloads\desert.gif") l = label(t, image=p) t.wm_title("school test")  var = stringvar(l) var.set("select test type.") # initial value  option = optionmenu(l, var, "text caps", "text mistakes") option.pack(expand=y)   b = button(l, text="start", command = lambda:type()) b.configure(background='peachpuff') b.pack(expand=y)  l.pack_propagate(0) l.pack()  t.mainloop() 

the problem is, when run code , select option optionmenu, button "start" disappears. how make button not disappear?

when change code to:(widgets in main frame(t) not in label(l) in code)

def type():     variable=var.get()     if variable=="text caps":         import caps_main.py   tkinter import * t = tk() t.geometry("500x300") p = photoimage(file="c:\users\indrek\downloads\desert.gif") l = label(t, image=p) t.wm_title("school test")  var = stringvar(t) var.set("select test type.") # initial value  option = optionmenu(t, var, "text caps", "text mistakes") option.pack(expand=y)   b = button(t, text="start", command = lambda:type()) b.configure(background='peachpuff') b.pack(expand=y)  l.pack_propagate(0) l.pack()  t.mainloop() 

then works, dont want buttons have such solid stripes background. want buttons on background image.

there couple of things suspicious in code. first, turn pack propagation off in label. means label won't resize based on widgets inside label. thus, if label tiny, hide menu you've packed in label. guess is, that's what's happening. without knowing size of image can't certain.

the second problem when pack label in container, don't specify options such expand , fill, won't grow fill main window.

if you're wanting use background image whole gui, don't have add label , add widgets label. simpler approach use place have label fill main window, , pack or grid other widgets in main window normal. 1 case place little better grid or pack.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -