当我从第一帧中销毁小部件时,我希望下一帧中的下一个元素替换它们,但它们会在页面中向下移动一半。我不知道为什么会发生任何想法?问题是围绕var_state1,但我不确定。当我将run2放进去时,它只是删除一个小部件而不是全部。
from tkinter import PhotoImage
from tkinter.ttk import *
from time import strftime
from tkinter import ttk
import tkinter
root = tkinter.Tk()
varp = 0
btn_style=Style()
btn_style.configure('TButton', font =
('calibri', 20, 'bold'),
borderwidth = '4')
class Frame1(tkinter.Frame):
def __init__(self, parent, *args, **kwargs):
tkinter.Frame.__init__(self, parent, *args, **kwargs)
self.Lab1 = Label(self, text="Check When Complete123:").grid(row=1, sticky=W)
self.Lab2 = Checkbutton(self, text="Turn On Icecream Mashine", command=self.check_plus1).grid(row=2, sticky=W)
self.Lab3 = Checkbutton(self, text="Turn On Radio", command=self.check_plus1).grid(row=3, sticky=W)
self.Lab4 = Checkbutton(self, text="Turn On Oven", command=self.check_plus1).grid(row=4, sticky=W)
self.Lab5 = ttk.Button(self, text="Done", command=self.var_state1, style="C.TButton").grid(row=5, sticky=W, pady=4)
def check_plus1(self):
global varp
if varp <= 3:
varp = varp + 1
def var_state1(self):
global varp
if varp >= 3:
print("it workd1")
for widget in Frame1.winfo_children(self):
widget.destroy()
run2()
class Frame2(tkinter.Frame):
def __init__(self, parent, *args, **kwargs):
tkinter.Frame.__init__(self, parent, *args, **kwargs)
Label(self, text="Check When Complete:").grid(row=0, sticky=W)
Checkbutton(self, text="Cleen The Tables", command=self.check_plus2).grid(row=1, sticky=W)
Checkbutton(self, text="Fill The Sauces ex: Caramell, Hot Fudge...", command=self.check_plus2).grid(row=2, sticky=W)
Checkbutton(self, text="Fill Spoons", command=self.check_plus2).grid(row=3, sticky=W)
Checkbutton(self, text="Deep Clean The Bottem Of The Toppings Freaser", command=self.check_plus2).grid(row=4, sticky=W)
Checkbutton(self, text="Fill The Toppings", command=self.check_plus2).grid(row=5, sticky=W)
crl2 = ttk.Button(self, text="Done", command=self.var_state2, style="C.TButton").grid(row=6, sticky=W, pady=4)
def check_plus2(self):
global varp
if varp <= 3:
varp = varp + 1
def var_state2(self):
global varp
if varp >= 5:
print("it worked2")
Close_Day()
def run1():
MyFrame1 = Frame1(root)
MyFrame1.pack(expand='true',fill='both')
root.mainloop()
def run2():
MyFrame2 = Frame2(root)
MyFrame2.pack(expand='true', fill='both')
root.mainloop()
run1()