Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[Python]Write a GUI class Game that implements a number guessing game. The GUI s

ID: 3840280 • Letter: #

Question

[Python]Write a GUI class Game that implements a number guessing game. The GUI should start by choosing a random number between 1 and 100 (using a function from the random module) and then opening up a GUI which allows the user to enter number guesses:
The GUI has an Entry widget for the user to type the number guess and a Button widget labeled "Enter" to enter the guess. The user should be able to enter guesses until he/she makes the correct guess. The GUI should keep track of the number of guesses it takes the user to reach the correct value. Your GUI should be user friendly and erase the guess each time the user presses the Enter button. This means that the user will not need to erase the old guess in order to enter a new one. Each time the user makes a guess, the GUI should indicate whether the user needs to guess higher or lower using a separate window. For example, the window showing that a guess of 50 was too high can be seen below:
If the guess is correct, a separate window should inform the user that she/he has guessed the number and display the number of guesses it took to get there. The following shows that window:

Further, the GUI should handle the cases where the user doesn't enter a number using exception handling. Invalid values shouldn't count toward the total number of guesses. Only valid numerical values should be counted. For example, suppose the user enters the following information:
When the user presses enter, the following window should be displayed:
After the user dismisses either the invalid number window or the incorrect guess window, the GUI should erase the text typed by the user and allow the user to enter a guess again:

Once the user has correctly guessed the value, the GUI should choose a new random value and allow the user to restart the game. This should be done by calling the new_game() method in the appropriate place in the event handler. You should start with the template provided in the template file. It shows the organization of the Game class, including the methods you are expected to write. The constructor has been implemented for you and shouldn't be changed unless you want to use grid instead of pack as your geometry manager. You should test your class by writing: Game().mainloop(). Use this template. Below are the examples of how it should run.

# Question 1
class Game(Frame):
    'Number guessing application'

    # You can change the geometry manager to grid if you like, but
    # otherwise don't change this method
    def __init__(self,parent=None):
        'constructor'
        Frame.__init__(self, parent)
        self.pack()
        self.count = 0
        Game.make_widgets(self)
        Game.new_game(self)

Enteryour guess Enter Enter your guess Enter Repot You got 5listoo hich, ktookyou tries idrumber Enter your guess Enter

Explanation / Answer

At the moment i ahve a task where i have to make a guessing game in GUI python. So it will generate a random number and also when a certain number of tries have been reached it will stop. The problems i am having as of now is that:
1) The counter when adding 1 simply goes, 111111
2) it always says lower even if i type 1

Here is my coding for now

# Guessing Game
# Demonstrates text and entry widgets, and the grid layout manager.

from Tkinter import *
import random

class Application(Frame):
""" GUI application which can retrieve an autp number to guess. """
def __init__(self, master):
""" Initialize the frame. """
Frame.__init__(self, master)
self.grid()
self.create_widgets()

def create_widgets(self):
""" Create button, text, and entry widgets. """

""" Instruction Label """

# Create instruction label for Program
self.inst_lbl = Label(self, text = "Follow the Steps")
self.inst_lbl.grid(row = 0, column = 0, columnspan = 2, sticky = W)


""" Player Name """

# Create label for name
self.name_lbl = Label(self, text = "Player Name: ")
self.name_lbl.grid(row = 1, column = 0, sticky = W)

# Create entry widget to accept name
self.name_ent = Entry(self)
self.name_ent.grid(row = 1, column = 1, sticky = W)


""" Guess Input """

# Create label for entering Guess
self.guess_lbl = Label(self, text = "Enter your Guess.")
self.guess_lbl.grid(row = 3, column = 0, sticky = W)

# Create entry widget to accept Guess
self.guess_ent = Entry(self)
self.guess_ent.grid(row = 3, column = 1, sticky = W)

# Create a space
self.gap1_lbl = Label(self, text = " ")
self.gap1_lbl.grid(row = 4, column = 0, sticky = W)

""" Submit Button """

# Create submit button
self.submit_bttn = Button(self, text = "Submit", command = self.reveal)
self.submit_bttn.grid(row = 5, column = 0, sticky = W)

# Create a space
self.gap2_lbl = Label(self, text = " ")
self.gap2_lbl.grid(row = 6, column = 0, sticky = W)

""" Display """

# Create text widget to display welcome_msg
self.display1_txt = Text(self, width = 45, height = 1, wrap = WORD)
self.display1_txt.grid(row = 7, column = 0, columnspan = 2, sticky = W)


# Create text widget to display welcome_msg
self.display2_txt = Text(self, width = 45, height = 1, wrap = WORD)
self.display2_txt.grid(row = 8, column = 0, columnspan = 2, sticky = W)

# Create text widget to display welcome_msg
self.display3_txt = Text(self, width = 45, height = 2, wrap = WORD)
self.display3_txt.grid(row = 9, column = 0, columnspan = 2, sticky = W)

# Create text widget to display welcome_msg
self.display4_txt = Text(self, width = 45, height = 2, wrap = WORD)
self.display4_txt.grid(row = 10, column = 0, columnspan = 2, sticky = W)


def reveal(self):

name = self.name_ent.get()
guess = self.guess_ent.get()
welcome_msg = "Welcome " + name
guess_msg = " Your guess was: " + guess
number = 10

tries = 1
tries = str(tries)
tries_msg = 0
tries_msg = str(tries_msg)
tries_msg = int(tries_msg) + int(tries)

if guess > number:
result_msg = "Lower ..."
elif guess < number:
result_msg = "Higher ..."
else:
result_msg = "You got it."


# Display
self.display1_txt.delete(0.0, END)
self.display1_txt.insert(0.0, welcome_msg)
self.display2_txt.delete(0.0, END)
self.display2_txt.insert(0.0, guess_msg)
self.display3_txt.delete(0.0, END)
self.display3_txt.insert(0.0, result_msg)
self.display4_txt.insert(0.0, tries_msg)


# Main manager
root = Tk()
root.title("Guessing Game")
root.geometry("300x200")

app = Application(root)

root.mainloop()


i believe the error is in the lines

tries = 1
tries = str(tries)
tries_msg = 0
tries_msg = str(tries_msg)
tries_msg = int(tries_msg) + int(tries)

if guess > number:
result_msg = "Lower ..."
elif guess < number:
result_msg = "Higher ..."
else:
result_msg = "You got it."

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote