這是一個小程序,當我從下拉菜單中選擇一個選項時,我可以找到不同四邊形的區域。但是,當我從假設廣場梯形切換,我得到這個:Python 3.4 tkinter,從菜單中選擇一個選項後沒有清除框架
我要清除的窗口只剩下選定的選項。
下面是代碼:
from tkinter import *
def square():
ment = IntVar()
def mhello():
mtext = ment.get()
mtext *= 2
mlabel2 = Label(mGui, text=mtext).pack()
mlabel = Label(mGui, text="Square").pack()
mbutton = Button(mGui, text= "Submit", command = mhello). pack()
nEntry = Entry(mGui, textvariable=ment).pack()
def rectangle():
oneMent = IntVar()
twoMent = IntVar()
def mhello():
oneMtext = oneMent.get()
twoMtext = twoMent.get()
mtext = 0
mtext = oneMtext * twoMtext
mlabel2 = Label(mGui, text=mtext).pack()
mlabel = Label(mGui, text="Rectangle/Parallelogram").pack()
mbutton = Button(mGui, text= "Submit", command = mhello). pack()
oneEntry = Entry(mGui, textvariable=oneMent).pack()
twoEntry = Entry(mGui, textvariable=twoMent).pack()
def trapezium():
oneMent = IntVar()
twoMent = IntVar()
threeMent = IntVar()
def mhello():
oneMtext = oneMent.get()
twoMtext = twoMent.get()
threeMtext = threeMent.get()
mtext = 0
mtext = oneMtext + twoMtext
mtext /= 2
mtext *= threeMtext
mlabel2 = Label(mGui, text=mtext).pack()
mlabel = Label(mGui, text="Trapezium").pack()
mbutton = Button(mGui, text= "Submit", command = mhello). pack()
oneEntry = Entry(mGui, textvariable=oneMent).pack()
twoEntry = Entry(mGui, textvariable=twoMent).pack()
threeEntry = Entry(mGui, textvariable=threeMent).pack()
def rhombus():
oneMent = IntVar()
twoMent = IntVar()
def mhello():
oneMtext = oneMent.get()
twoMtext = twoMent.get()
mtext = 0
mtext = oneMtext * twoMtext
mtext /= 2
mlabel2 = Label(mGui, text=mtext).pack()
mlabel = Label(mGui, text="Rhombus").pack()
mbutton = Button(mGui, text= "Submit", command = mhello). pack()
oneEntry = Entry(mGui, textvariable=oneMent).pack()
twoEntry = Entry(mGui, textvariable=twoMent).pack()
def restart():
mGui.destroy()
mGui = Tk()
mGui.geometry("450x450+500+300")
mGui.title("Square Area Finder")
mHomeLabel = Label(mGui, text="Use the drop down menu to select the quadrilateral you want to find the area of.").pack()
menu = Menu(mGui)
mGui.config(menu=menu)
file =Menu(menu)
file.add_command(label="Square", command=square)
file.add_command(label="Rectangle/Parallelogram", command=rectangle)
file.add_command(label="Trapezium", command=trapezium)
file.add_command(label="Rhombus", command=rhombus)
file.add_separator()
file.add_command(label="Quit", command=restart)
menu.add_cascade(label="Options", menu=file)
mGui.mainloop()
謝謝你給任何人,可以幫助。
我沒有看到任何地方,你甚至嘗試清除窗口。 –
@BryanOakley我已經添加到他的代碼 –