好吧,所以我有一個帶有編輯和查看按鈕的基本窗口。正如我的代碼所示,編輯和查看都返回一條消息「這個按鈕是無用的」。我在類「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