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

时间:2012-08-20 21:45:55

标签: python mysql-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()

1 个答案:

答案 0 :(得分:2)

尝试将命令拆分为函数:

def clear_textbox():
    b1.delete(0, END)

bu2 = Button(app, text='CLEAR', command=clear_textbox)
相关问题