好吧,所以我有一个带有编辑和查看按钮的基本窗口。正如我的代码所示,编辑和查看都返回一条消息“这个按钮是无用的”。我在类“main_window”下创建了这些。我创建了另一个类“edit_window”,我希望在点击EDIT按钮时调用它。本质上,点击编辑按钮应该改变显示新的窗口与按钮添加和删除。这是我的代码到目前为止......下一个合乎逻辑的步骤是什么?很难理解python中的Tkinter主循环()
from Tkinter import *
#import the Tkinter module and it's methods
#create a class for our program
class main_window:
def __init__(self, master):
frame = Frame(master)
frame.pack(padx=15,pady=100)
self.edit = Button(frame, text="EDIT", command=self.edit)
self.edit.pack(side=LEFT, padx=10, pady=10)
self.view = Button(frame, text="VIEW", command=self.view)
self.view.pack(side=RIGHT, padx=10, pady=10)
def edit(self):
print "this button is useless"
def view(self):
print "this button is useless"
class edit_window:
def __init__(self, master):
frame = Frame(master)
frame.pack(padx=15, pady=100)
self.add = Button(frame, text="ADD", command=self.add)
self.add.pack()
self.remove = Button(frame, text="REMOVE", command=self.remove)
self.remove.pack()
def add(self):
print "this button is useless"
def remove(self):
print "this button is useless"
top = Tk()
top.geometry("500x500")
top.title('The Movie Machine')
#Code that defines the widgets
main = main_window(top)
#Then enter the main loop
top.mainloop()
你对主流程有什么不了解?对我来说,你似乎在寻找[Toplevel](http://effbot.org/tkinterbook/toplevel.htm),通过它你可以使edit_window成为一个单独的窗口。 – Junuxx 2013-03-05 23:46:44
我可能没有解释得很好。我希望主窗口根据您点击的按钮进行更新。所以我不想打开一个新窗口,如果我点击编辑,我想现有的窗口显示编辑和查看---它应该更新显示添加删除与它以前显示编辑查看相同的方式。合理?所以我假设Toplevel只是用ADD REMOVE打开一个新窗口。 – ordanj 2013-03-06 03:13:17