如何临时使Button
完全填满整个gui,然后在按下所述按钮后返回到先前的状态。
我尝试将按钮设置为“最高级别”框架,并使用“扩展和填充”配置设置,这使Button
变得相当大,但最终它仅占GUI底部的1/3。 / p>
... other instantiations...
#Initialization of button in gui as whole
toggleBacklightButton = Button(patternOptionFrame,text="Screen Light",
font=('calibri',(10)),relief="raised",
command=toggleBacklight)
toggleBacklightButton.grid(row=0,column=3)
... other code...
#Function that the button press calls.
def toggleBacklight():
global backlight_toggle
backlight_toggle = not backlight_toggle
if backlight_toggle is True:
# Button should be as it was when instantiated AND back light
# is on / all other ~20 widgets are also where they belong.
os.system(
"sudo sh -c 'echo \"0\" > /sys/class/backlight/rpi_backlight/bl_power'")
else:
# Button should fill entire screen for ease of access when
# screen is black / all other ~20 widgets are hidden.
os.system(
"sudo sh -c 'echo \"1\" > /sys/class/backlight/rpi_backlight/bl_power'")
... other functions...
该按钮确实可以切换我的触摸屏显示,但是,当屏幕背光关闭时,我不知道如何使它占据整个屏幕。
答案 0 :(得分:1)
Tkinter通常根本不允许小部件重叠-使按钮变大只会将其他小部件推开,它实际上不会覆盖它们。在您极少数情况下想要重叠的情况下,只有.place()
几何图形管理器可以做到。将按钮设为窗口本身的直接子代,然后执行以下操作:
toggleBacklightButton.place(x=0, y=0, relwidth=1.0, relheight=1.0)
使其接管窗口,然后:
toggleBacklightButton.place_forget()
摆脱它。
答案 1 :(得分:0)
如果要使用重叠的小部件,则将所有内容构建在框架内部,然后将按钮放在框架的同一网格位置。
类似这样的东西:
import tkinter as tk
root = tk.Tk()
def action():
btn.destroy()
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
frame = tk.Frame(root)
frame.grid(row=0, column=0, sticky="nsew")
tk.Label(frame, text="some random label").pack()
btn = tk.Button(root, text="Some big button", command=action)
btn.grid(row=0, column=0, sticky="nsew")
root.mainloop()