Skip to content

Commit 7df3b10

Browse files
Merge pull request #2471 from avinashkranjan/deepsource-transform-21c9f233
format code with autopep8
2 parents 07912a9 + dd13d32 commit 7df3b10

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Hangman_Gui/hangman_gui.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import tkinter as tk
33
from tkinter import messagebox
44

5+
56
def choose_word():
67
words = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape"]
78
return random.choice(words)
89

10+
911
class HangmanGame:
1012
def __init__(self, master):
1113
self.master = master
@@ -22,7 +24,8 @@ def __init__(self, master):
2224
self.entry_guess = tk.Entry(master)
2325
self.entry_guess.pack()
2426

25-
self.button_guess = tk.Button(master, text="Guess", command=self.make_guess)
27+
self.button_guess = tk.Button(
28+
master, text="Guess", command=self.make_guess)
2629
self.button_guess.pack()
2730

2831
def display_word(self):
@@ -38,34 +41,41 @@ def make_guess(self):
3841
guess = self.entry_guess.get().lower()
3942

4043
if len(guess) != 1 or not guess.isalpha():
41-
messagebox.showwarning("Invalid Input", "Please enter a single letter.")
44+
messagebox.showwarning(
45+
"Invalid Input", "Please enter a single letter.")
4246
return
4347

4448
if guess in self.guessed_letters:
45-
messagebox.showinfo("Already Guessed", "You've already guessed this letter.")
49+
messagebox.showinfo("Already Guessed",
50+
"You've already guessed this letter.")
4651
return
4752

4853
self.guessed_letters.append(guess)
4954

5055
if guess not in self.word:
5156
self.attempts += 1
52-
self.label_attempts.config(text=f"Attempts left: {6 - self.attempts}")
57+
self.label_attempts.config(
58+
text=f"Attempts left: {6 - self.attempts}")
5359

5460
self.label_word.config(text=self.display_word())
5561

5662
if "_" not in self.display_word():
57-
messagebox.showinfo("Congratulations!", f"You guessed the word: {self.word}")
63+
messagebox.showinfo("Congratulations!",
64+
f"You guessed the word: {self.word}")
5865
self.master.destroy()
5966

6067
if self.attempts >= 6:
61-
messagebox.showinfo("Game Over", f"Out of attempts! The word was: {self.word}")
68+
messagebox.showinfo(
69+
"Game Over", f"Out of attempts! The word was: {self.word}")
6270
self.master.destroy()
6371

72+
6473
def main():
6574
root = tk.Tk()
6675
root.title("Hangman Game")
6776
game = HangmanGame(root)
6877
root.mainloop()
6978

79+
7080
if __name__ == "__main__":
7181
main()

0 commit comments

Comments
 (0)