【发布时间】:2020-07-06 19:44:33
【问题描述】:
每当我使用 destroy() 函数删除 tkinter 中的按钮时,该按钮下方的 tkinter gui 窗口中的所有其他小部件都会向上移动,从而在我的屏幕底部创建一个间隙。我不希望这种情况发生。删除按钮后有什么方法可以防止小部件移动?另请注意,我必须将按钮放在放置在框架中的标签中,并且该框架位于主 gui 窗口中。这些是约束。
enter code here
from tkinter import *
screen = Tk()
screen.title("Kaun Banega Crorepati - The Game")
screen.geometry('1920x1080+0+0')
gameframe = Frame(screen, bg='#2e004d',width=1920,height=1080)
gameframe.pack()
panel = Label(gameframe, bg='#2e004d', width=1920, height=1080)
panel.pack()
def cmd():
optionc.destroy()
optiona = Button(panel, text='A.option', font='Arial 18 bold', bg='black',
fg='yellow')
optiona.pack(side='top', padx=40,pady=20)
optionb = Button(panel, text='B.option', font='Arial 18 bold', bg='black',
fg='yellow')
optionb.pack(side='top', padx=40,pady=20)
optionc = Button(panel, text='C.option', font='Arial 18 bold', bg='black',
fg='yellow')
optionc.pack(side='top', padx=40,pady=20)
optiond = Button(panel, text='D.option', font='Arial 18 bold', bg='black',
fg='yellow')
optiond.pack(side='top', padx=40,pady=20)
destroybutton=Button(panel,text='destroy',font='Arial 18 bold', bg='black',
fg='yellow',border=5,command=cmd)
destroybutton.pack(side='top', padx=40,pady=20)
screen.mainloop()
【问题讨论】:
标签: python python-3.x tkinter tkinter-layout