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

  • Home
  • SEARCH
  • 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 7956971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:09:23+00:00 2026-06-04T04:09:23+00:00

So in my program, whenever I put the grid_remove() function it usually deletes the

  • 0

So in my program, whenever I put the grid_remove() function it usually deletes the widget. Whenever I run the program for the first time (that is, not losing any points by guessing wrongly), it deletes most of the widgets. However, whenever I guess wrong and get points taken away (which works fine), the widgets lazily remain on the window. Any help?

Here’s the code: (I think that the error occurs somewhere after def numright and def wordguess)

import random
from tkinter import *
from tkinter import messagebox

text_doc = open("test.txt", "r")
text = text_doc.read()
numbOfletters = len(text)
random_letter = random.randint(0,numbOfletters-1)
letter = text[random_letter]
points = 50
username = ""
is_there = 0

class GUIFramework(Frame):

    def __init__(self,master=None):

        Frame.__init__(self,master)

        self.master.title("Window")
        self.master.geometry("420x75")

        self.grid(padx=10,pady=10)
        self.CreateWidgets()

    def CreateWidgets(self):

        self.lbText = Label(self, text="Would you like to play \"Find the secret letter?\"", font="Verdana")
        self.lbText.grid(row=0, column=0, columnspan = 3)

        self.button = Button(self, text="Yes, please", command=self.next, background = "green")
        self.button.grid(row=1, column=0)

        self.btnDisplay = Button(self, text="No, thanks", command = self.window, background = "red")
        self.btnDisplay.grid(row=1, column=1)

    def window(self):

        self.tl = Toplevel(self)
        self.master.destroy()

    def next(self):

        self.lbText.grid_remove()
        self.button.grid_remove()
        self.btnDisplay.grid_remove()

        self.lbText = Label(self, text="You're currently playing \"Find the secret letter\"", font="Verdana")
        self.lbText.grid(row=0, column=0, columnspan = 10)

        self.username = Label(self, text="Enter your username")
        self.username.grid(row=1, column=0)

        self.enText = Entry(self)
        self.enText.grid(row=1, column=2, columnspan=5)

        self.ok = Button(self, text="OK", command = self.wordguess)
        self.ok.grid(row=1, column=8)


    def wordguess(self):

        global username
        self.master.geometry("420x90")
        username = self.enText.get()

        self.username.grid_remove()
        self.enText.grid_remove()

        self.word = Label(self, text="You have {0} points, enter a word?".format(50))
        self.word.grid(row=1, column=0)

        self.entry = Entry(self)
        self.entry.grid(row=1, column=1, columnspan=4)

        self.ok = Button(self, text="OK", command = self.numright)
        self.ok.grid(row=1, column=8)

    def numright(self):

        global points
        global is_there

        word = self.entry.get()
        word = word.lower()
        is_there = word.count(letter)

        self.lbText.grid_remove()
        self.word.grid_remove()
        self.entry.grid_remove()
        self.enText.grid_remove()
        self.ok.grid_remove()

        if is_there > 4:
            self.master.geometry("200x70")
            self.done = Label(self, text = "Congradulations, you have won!")
            self.done.grid(row = 0, column = 0)

            self.ok = Button(self, text="OK", command = self.window)
            self.ok.grid(row=1, column=0)

        else:
            if (is_there < 5) and (is_there > 0):
                points = points - 5

            else:
                points = points - 10

            self.lbText = Label(self, text="You're currently playing \"Find the secret letter\"", font="Verdana")
            self.lbText.grid(row=0, column=0, columnspan = 10)

            self.numright = Label(self, text="That word has {} secret letters".format(is_there))
            self.numright.grid(row=2, column=0)

            self.word = Label(self, text="You have {0} points, enter a word?".format(points))
            self.word.grid(row=1, column=0)

            self.entry = Entry(self)
            self.entry.grid(row=1, column=1, columnspan=4)



    def scores(self):
        output = open("names.txt", "a")
        output.write("{0:2}      {1} \n".format(str(points), username))
        output.close()
        output = open("names.txt", "r")




if __name__ == "__main__":
    guiFrame = GUIFramework()
    guiFrame.mainloop()
  • 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-04T04:09:25+00:00Added an answer on June 4, 2026 at 4:09 am

    Your problem is the lines (in the else clause of the numright method):

            self.numright = Label(self, text="That word has {} secret letters".format(is_there))
            self.numright.grid(row=2, column=0)
    

    self.numright is a method in your GUIFramework class, which you stomp on here and reassign it to a Label field. Also you probably have to put the self.ok button back onto the page since you grid_removed it above. I added the lines:

    self.ok = Button(self, text="OK", command = self.numright)
    self.ok.grid(row=1, column=8)
    

    to the end of the numright method to put the OK button back. I then fiddled about by making a different method which just called self.numright which is how I caught the reassignment bug.

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

Sidebar

Related Questions

Whenever I run any jython program in Eclipse, I got the following error in
I got a program that whenever I minimize it, it goes to the system
What I want is that when Activity starts first time, it first checks if
I have some code that I want to run in a utility application whenever
I'm writing an MPI C program. I have troubles debugging it, because whenever I
This program I use has it's own variables to set when you run it,
My program opens a socket on port 80, but if I don't run it
I'm trying to put a code on a button so that the user would
We've got a program that runs on our network (it's published to our app-server
I have a structure in my program that contains a particular array. I want

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.