当我在a
小部件中输入输入值Entry
并点击Click Me
时。此按钮调用更新takes_input()
小部件的Text
方法。看起来像这样:
再次输入下一个输入值b
,它附加了之前的值,如下所示:
我的代码:
from tkinter import *
# def func for button callback
def takes_input():
textBox.insert(INSERT, inputBox_val.get())
# object for windows
window = Tk()
window.title("Learning GUI")
inputBox_val = StringVar()
# create button on windows
myBtn = Button(window, text="Click Me", command = takes_input)
myBtn.grid(row = 0, column = 0)
# input filed
inputBox = Entry(window, textvariable = inputBox_val)
inputBox.grid(row = 0, column = 1)
# textBox filed
textBox = Text(window, height = 1, width = 20)
textBox.grid(row = 0, column =2)
window.mainloop()
问题是:
当我再次点击Entry
按钮时,我想要清除Click Me
小部件的先前输入。
我是怎么做到的?
答案 0 :(得分:1)
您必须使用delete('1.0', END)
清除文字。在你的情况下:
def takes_input():
textBox.delete('1.0', END)
textBox.insert(INSERT, inputBox_val.get())