显示了窗口小部件,但按钮不执行任何操作。为什么?代码不对吗?在某些IDE中,您根本无法导入tkinter
# import tkinter
from tkinter import *
# ven Widget
ven = Tk()
boton = Button(ven, text="hola", command="cerrar")
boton.pack()
# function
def cerrar():
ven.destroy
ven.mainloop()
答案 0 :(得分:1)
@HenryYik在评论中说了什么:
command = cerrar不带双引号。并移动您的功能cerrar 按钮创建上方
import tkinter as tk
def cerrar():
ven.destroy() # add parens to call the method
ven = tk.Tk()
boton = tk.Button(ven, text="hola", command=cerrar)
boton.pack()
ven.mainloop()