分类: Python/Ruby
2014-03-04 14:33:32
tkMessageBox作为建立界面的框架。这个时候是不会出现上面的窗体关闭按钮。这样就是退出只能是退出提示
你退出,界面就会彻底退出。
2,关联窗体上回调函数:
这个就是类Qt中的closeEvent内部函数(虚函数)。你必须在窗体中添加这个相应的虚函数。在窗体关闭时候
界面就会退出
举个例子:
#===============================================================
#programer jjw
#20130304
#===============================================================
import Tkinter as tk
from ScrolledText import ScrolledText
class exp_App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.title('Test')
self.protocol("WM_DELETE_WINDOW", self.close)
# make Esc exit the program
self.bind('', lambda e: self.destroy())
# create a menu bar with an Exit command
menubar = tk.Menu(self)
filemenu = tk.Menu(menubar, tearoff=0)
filemenu.add_command(label="Exit", command=self.destroy)
menubar.add_cascade(label="File", menu=filemenu)
self.config(menu=menubar)
txt = ScrolledText(self, undo=True)
txt['font'] = ('consolas', '12')
txt.pack(expand=True, fill='both')
def close(self):
self.destroy
self.quit
self.print_name()
def print_name(self):
print "you can add the others functions here if you want "
if __name__ == "__main__": app = exp_App() app.mainloop()
一定要将你的事件事件函数绑定到你的关联函数中