O

 avatar
unknown
plain_text
5 months ago
1.4 kB
5
Indexable
import tkinter as tk

# Game class to encapsulate the clicker game logic
class ClickerGame:
    def __init__(self, root):
        self.root = root
        self.root.title("Clicker Game")

        # Initialize score
        self.score = 0

        # Create label for score display
        self.score_label = tk.Label(self.root, text=f"Score: {self.score}", font=("Arial", 20))
        self.score_label.pack(pady=20)

        # Create a button that users click to earn points
        self.click_button = tk.Button(self.root, text="Click Me!", command=self.increase_score, font=("Arial", 16), bg="blue", fg="white", height=3, width=15)
        self.click_button.pack(pady=20)

        # Create a reset button to reset the score
        self.reset_button = tk.Button(self.root, text="Reset Score", command=self.reset_score, font=("Arial", 16), bg="red", fg="white", height=2, width=10)
        self.reset_button.pack(pady=10)

    # Method to increase score
    def increase_score(self):
        self.score += 1
        self.update_score()

    # Method to update the score on the label
    def update_score(self):
        self.score_label.config(text=f"Score: {self.score}")

    # Method to reset the score
    def reset_score(self):
        self.score = 0
        self.update_score()

# Set up the main application window
root = tk.Tk()

# Create an instance of the ClickerGame
game = ClickerGame(root)

# Run the Tkinter event loop
root.mainloop()
Editor is loading...
Leave a Comment