这是我的代码的简短形式。在 [ input
] 窗口中,我希望它只弹出 [ ] 窗口,点击按钮后会弹出input2
[ ] 窗口。solve
Solve!
但是,目前,[ input2
] 和 [ solve
] 窗口同时弹出,并且Solve!按钮在单击时不执行任何操作。
这是我的代码:
from tkinter import *
class welcome():
def __init__(self, master): #master: root - the main window
# welcome and introduction
self.master=master
self.master.geometry("500x200")
self.welcome = Label(self.master, text="Welcome to The Bees's")
self.welcome.pack()
self.intro = Label(self.master, text="This is our project for Python course")
self.intro.pack()
self.intro2 = Label(self.master, text="This program is use for solving Linear Programming, IP, BIP, mixed... problem")
self.intro2.pack()
self.startbutton = Button(self.master, text="Start", bg="yellow")
self.startbutton.pack()
self.startbutton.config(command=self.gotoinput)
def gotoinput(self):
root2 = Toplevel(self.master)
self.input1=input(root2)
输入窗口类:
class input():
def __init__(self,master):
self.master=master
self.master.title("Input")
self.master.geometry("700x500")
#cancle
self.Canclebutton=Button(self.master,text="Cancle",command=self.master.destroy).grid(row=3,column=1)
#OK
self.Enterbutton=Button(self.master,text="ENTER",command=self.gotoinput2).grid(row=3,column=2)
def gotoinput2(self):
root3=Toplevel(self.master)
self.input22=input2(root3)
input2 窗口的类:
class input2():
def __init__(self,master):
self.master=master
self.master.title("Input2")
self.master.geometry("700x500")
# cancle
self.Canclebutton = Button(self.master, text="Cancle", command=self.master.destroy).grid(row=0, column=0)
# OK
self.Solvebutton = Button(self.master, text="Solve!", command=self.gotosolve()).grid(row=0, column=1)
print("Through")
def gotosolve(self):
print("gotosolve")
root4=Toplevel(self.master)
self.solve11=solve(root4)
求解窗口的类:
class solve():
def __init__(self,master):
self.master = master
self.master.title("Solution")
self.master.geometry("700x500")
# cancle
self.Canclebutton = Button(self.master, text="Cancle", command=self.master.destroy).grid(row=0,column=0)
主功能:
def main():
# create a main window
root = Tk()
root.title("The Bees's")
b = welcome(root)
# end line
root.mainloop()
main()