Python 3基础教程35-tkinter事务处理

xiaoxiao2021-02-28  56

在前面的代码基础上,本文来介绍tkinter的事务处理,我们这样来做,点击退出按钮,也能执行关闭窗体的动作。

# tkinter 模块添加一个按钮 from tkinter import * class Window(Frame): def __init__(self, master= None): Frame.__init__(self, master) self.master = master self.init_window() def init_window(self): self.master.title("第一个窗体") self.pack(fill=BOTH, expand=1) # 添加一个command,进行事务处理,这里点击退出,执行退出程序 quitButton = Button(self, text="退出",command=self.client_exit) quitButton.place(x=0,y=0) def client_exit(self): exit() root = Tk() root.geometry("400x300") app = Window(root) root.mainloop() 运行后,弹出一个对话框,让你确定是否要退出程序。

转载请注明原文地址: https://www.6miu.com/read-83770.html

最新回复(0)