Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[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

[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)

# Write this method def make_widgets(self): 'defines Game widgets' # Write this method def new_game(self): 'starts new game by choosing a secret number and resetting the count' #Used to get vars def cmd(self): self.reply(self.guessEntry.get()) # Write this method def reply(self, x): 'handles button "Enter" clicks'image text in transcribed

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Lo6 Identify several management development methods.

Answered: 1 week ago