Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset textboxes in Python [closed]

A few weeks ago I asked for some help in making a reset button, I'm new to python and a Noob in it, mostly I work in c++ & c# also SQL anyways I'm making a reset button for a game, and I cant get it to work. here is the code. The problem seems to be that it can't delete the text in the textboxes after it has been posted, but it can delete the labels and reset them. That the user inputs, the first to lines in def reset(self): that end with _ent are reseted but not the remaining textboxes.

    def reset(self):
       self.name_ent.delete(0, END)
       self.gissa_ent.delete(0, END)
       self.display1_txt.delete(0,END)
       self.display2_txt.delete(0,END)
       self.display3_txt.delete(0,END)
       self.display4_txt.delete(0,END)
   # Text for welcome messeage shown in a textbox
    self.display1_txt = Text(self, width = 45, height = 1, wrap = WORD)
    self.display1_txt.grid(row = 8, column = 0, columnspan = 2, sticky = W)

The error message I get is following and Yes I'm using Tkinter.

 File "/Users/andrej/Desktop/A.Curcic Laboration 3 SU", line 81, in reset
    self.display1_txt.delete(0,END)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 2915, in delete
    self.tk.call(self._w, 'delete', index1, index2)
TclError: bad text index "0"
like image 911
SterlinkArcher Avatar asked May 18 '26 02:05

SterlinkArcher


1 Answers

In Tkinter, text indexes are expressed as "row.column" (in your case "1.0"), see here.

Try

self.display1_txt.delete("1.0",END)
like image 141
Krumelur Avatar answered May 19 '26 16:05

Krumelur