How to clear the Entry widget after a button is pressed in Tkinter?

后端 未结 11 1078
渐次进展
渐次进展 2020-12-01 10:44

I\'m trying to clear the Entry widget after the user presses a button using Tkinter.

I tried using ent.delete(0, END), but I got an error

11条回答
  •  [愿得一人]
    2020-12-01 11:03

    real gets the value ent.get() which is just a string. It has no idea where it came from, and no way to affect the widget.

    Instead of real.delete(), call .delete() on the entry widget itself:

    def res(ent, real, secret):
        if secret == eval(real):
            showinfo(message='that is right!')
        ent.delete(0, END)
    
    def guess():
        ...
        btn = Button(ge, text="Enter", command=lambda: res(ent, ent.get(), secret))
    

提交回复
热议问题