我不知道我错了什么,但当用户单击按钮时,我使用此代码清除输入框文本。我已经完成了引用和所有内容,并且代码已编译,但按清除按钮不会清除输入框,并且我没有收到任何错误。你能帮忙吗?
from Tkinter import *
import Pmw
#=============================================================================
app = Tk()
app.title("Testing")
#the variable
bv = IntVar()
#the entry box
b1 = Entry(app, textvariable=bv)
b1.pack()
#=============================================================================
def test():
print bv.get()
#=============================================================================
bu1 = Button(app, text="PRESS", command=test)
#packing button 1
bu1.pack()
#button 2 referencing b1
bu2 = Button(app, text="CLEAR", command=b1.delete(0,END))
#packing button 2
bu2.pack()
#the mainloop
app.mainloop()
最佳答案
尝试将命令拆分为一个函数:
def clear_textbox():
b1.delete(0, END)
bu2 = Button(app, text='CLEAR', command=clear_textbox)
关于python - 单击按钮时清除输入框文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12045675/