-1

I am inputting a random number from 1 to 25 into a text box on button press. Every time i press the button, i want the text box to be emptied before the new number is stored - but putting self.outputbox.delete("1.0") into the button command only deletes the first character. i tried replacing 1.0 by something obvious like 2.0, but it never deleted both characters. At the moment, i am doing a very dirty solution by just calling self.outputbox.delete("1.0") twice - but i want to know how to delete the entire content of the text box.

this is the part:

   def change_button_color(self):
       randomcolor = self.get_random_color()
       randombutton = self.random_button()
       for z in range(0,1):
          self.buttons['button{}'.format(randombutton)].config(bg=randomcolor)
          for i in range(0,40):
              self.outputbox.delete("1.0")
          self.outputbox.insert("1.0","Button" + str(randombutton) + " " + "has the color" + " " + randomcolor)

as you can see, i currently have a rather dirty solution to clear the box

Flying Thunder
  • 890
  • 2
  • 11
  • 37

1 Answers1

1

Do this

self.outputbox.delete("1.0", self.END)

it will clear all the text widget

And if you imported tkinter as tk do this

self.outputbox.delete("1.0", self.tk.END)
AD WAN
  • 1,414
  • 2
  • 15
  • 28