I am trying to clear or reset a text box and store new results. Basically, every time i press the button, I would like the text box to be emptied before the new text is stored.
In my research the following thread popped up and he seems to have a similar goal however I wasn't sure how to apply that to my code. TKinter - Clear text widget
I've tried the following but it doesn't work for obvious reasons. Not sure how else to approach this.
button = tk.Button(root, command=lambda: button_cmmd())
def button_cmmd():
if len(text_widget_1.get("1.0", "end-1c")) <= 5:
#I get descriptions - this portion works.
else:
text_widget_2.delete("1.0", END)
EDIT A half solution I've worked is:
def button_cmmd():
if len(text_widget_2.get("1.0", "end-1c")) <= 2:
text_widget_1.get("1.0", "end-1c"))
else:
text_widget_2.delete("1.0", "end-1c")
A minor annoyance now is that clicking the button once will populate the text_box_2
, a 2nd click will delete that text so you have to click it a third time for it to run the .get
again.