Tkinter支持多种执行各种任务的方法。它还提供了一些通用方法。
destroy()是一种通用的窗口小部件方法,即我们可以将此方法与任何可用的窗口小部件以及主tkinter窗口一起使用。
用法:
widget_object = Widget(parent, command = widget_class_object.destroy)
此方法可以与after()方法一起使用。
代码1:作为命令传递的destroy()方法
# importing only those functions
# which are needed
from tkinter import *
from tkinter.ttk import *
# creating tkinter window
root = Tk()
# Creating button. In this destroy method is passed
# as command, so as soon as button 1 is pressed root
# window will be destroyed
btn1 = Button(root, text ="Button 1", command = root.destroy)
btn1.pack(pady = 10)
# Creating button. In this destroy method is passed
# as command, so as soon as button 2 is pressed
# button 1 will be destroyed
btn2 = Button(root, text ="B