Note that there are some explanatory texts on larger screens.

plurals
  1. POTkinter: how do you delete entry field without causing errors?
    primarykey
    data
    text
    <p>I am trying to remove an Entry field after a user gives his/her name, however, I get an error using this code:</p> <pre><code>from Tkinter import * from random import randrange class Application(Frame): def __init__(self): Frame.__init__(self) self.grid() self.nameEntry = Entry(self) self.nameEntry.grid(row=0, column=0, columnspan=4) self.setupBtn = Button(self, text = "Generate", command=self.setup) self.setupBtn.grid(row=4, column=0, columnspan=4) self.preText = Text(self, width=50, height=3, wrap=WORD) self.preText.grid(row=6, column=0, columnspan=4) self.preText.delete(0.0, END) self.preText.insert(0.0, "If you enter your name, i'll give you a random number each time!") self.statusLbl = Label(self, text="What's your name?", bg="white") self.statusLbl.grid(row=7, column=0, columnspan=4, sticky=W) def setup(self): name = self.nameEntry.get() if name != "": self.nameEntry.destroy() self.setupBtn = Button(self, text = "Roll Again", command=self.setup) self.setupBtn.grid(row=4, column=0, columnspan=4) randomNumber = randrange(10, 100) if name == "": message = "Your name please!" self.preText.delete(0.0, END) self.preText.insert(0.0, message) else: self.preText.delete(0.0, END) self.preText.insert(0.0, str(randomNumber)) Application().mainloop() </code></pre> <p>Here is the error:</p> <blockquote> <p>Exception in Tkinter callback Traceback (most recent call last):</p> <pre><code>File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__ return self.func(*args) File "C:/Users/User/Desktop/app.py", line 25, in setup name = self.nameEntry.get() File "C:\Python27\lib\lib-tk\Tkinter.py", line 2391, in get return self.tk.call(self._w, 'get') TclError: invalid command name ".45073096L.45073736L" </code></pre> </blockquote> <p>I would like to remove the name Entry field after a user enters the name and clicks the roll button. But instead of rolling, I get that error.</p> <p>Is anyone able to help me? From what I know, it is because <code>name = self.nameEntry.get()</code> is used to store into name and therefore, when I delete it, it causes a problem. Do you have a workaround for it? I am not very good and am therefore unsure of how to proceed.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload