Chinaunix首页 | 论坛 | 博客
  • 博客访问: 490925
  • 博文数量: 74
  • 博客积分: 750
  • 博客等级: 军士长
  • 技术积分: 1453
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-29 15:59
文章分类
文章存档

2014年(30)

2013年(8)

2012年(36)

分类: Python/Ruby

2014-03-04 14:33:32

Python 在建立界面模块的时候可能会出现,界面的窗体上的关闭按钮按下,界面退出后,但是再次启动的时候无法启动界面,
因为界面这个时候相当于做了隐藏,类似于Qt中的Held。
解决这样的问题。一般有以下办法:

1,可以在建立界面的时候用
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()
一定要将你的事件事件函数绑定到你的关联函数中
阅读(3594) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~