单击按钮时清除输入框文本

2024-05-15 13:36:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我不知道我做错了什么,但是当用户点击一个按钮时,我用这个代码清除了输入框的文本。我已经做了引用和所有的事情,代码编译,但按清除按钮并没有清除输入框,我没有得到任何错误。你能帮忙吗。

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()

Tags: the代码texttestimportappbutton按钮