Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7882943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:24:17+00:00 2026-06-03T04:24:17+00:00

I am trying to remove an Entry field after a user gives his/her name,

  • 0

I am trying to remove an Entry field after a user gives his/her name, however, I get an error using this 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() 

Here is the error:

Exception in Tkinter callback Traceback (most recent call last):

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"

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.

Is anyone able to help me? From what I know, it is because name = self.nameEntry.get() 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:24:19+00:00Added an answer on June 3, 2026 at 4:24 am

    Two choices here:

    (Quick & dirty) You could change the first if in setup() to be:

    if name != "":
        self.nameEntry.grid_forget()
        self.setupBtn.config(text="Roll Again")
    

    grid_forget() causes Tk to remove the widget but not actually destroy it. Also, you don’t need to recreate your button, you can just tell it to change its text. Another way to do it would be to set self.name=None in __init__ and change setup() to:

    def __init__(self):
        self.name=None
        # rest of __init__ the same
    
    def setup(self):
        if not self.name:
            self.name = self.nameEntry.get()
            self.nameEntry.destroy()
            self.setupBtn.config(text="Roll Again")
    
        randomNumber = randrange(10, 100)
        if not self.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))
    

    Unfortunately I’ve not found one good central source of info for Tkinter/ttk, but here are the ones I have found:

    • http://www.tkdocs.com/ (start here, tutorial has some great stuff)
    • http://effbot.org/tkinterbook/tkinter-index.htm (Tkinter docs)
    • http://docs.python.org/library/ttk.html#module-ttk (2.7 Python ttk module)
    • http://www.tcl.tk/man/tcl8.5/contents.htm (for really deep digging tcl/tk 8.5 docs)

    Use ttk widgets whenever you can, they make your apps look much more like native host apps. As for Tix, it’s there mostly for backwards compatibility.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to remove the actual box of a checkbox field, and just
This is a follow up to link text about trying to remove the stack
I'm trying to remove duplicates from a MySQL table using ALTER IGNORE TABLE +
Trying to make my project using storyboard. I changed my info.plist and added entry
The stock ELMAH_Error table uses an nText field to store an Error entry. I
I am trying to programmatically remove rows from a Microsoft Access Database using a
On my website, I am trying to remove (hide) an sql entry in a
I'm trying to remove any duplicate or more occurrences of any < br >
I'm trying to remove part of the path in a string. I have the
I'm trying to remove scrollbar from my facebook app. I tried js solution, that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.