import tkinter as tk
import random
import pygame
class PixelDestroyerGame:
def __init__(self, root):
self.root = root
self.root.title("Destroy the Screen!")
# Make window bigger
self.root.geometry("800x600")
# Initialize pygame mixer for sound
pygame.mixer.init()
self.click_sound = pygame.mixer.Sound("click.wav") # Add your sound file
here
# Canvas that covers the whole window
self.canvas = tk.Canvas(root, width=800, height=600, bg="black")
self.canvas.pack()
# Fill canvas with rectangles (simulate pixels)
self.pixel_size = 5 # Each "pixel" is 5x5
self.pixels = []
for x in range(0, 800, self.pixel_size):
for y in range(0, 600, self.pixel_size):
pixel = self.canvas.create_rectangle(
x, y, x + self.pixel_size, y + self.pixel_size,
fill="green", outline=""
)
self.pixels.append(pixel)
# Add a button in the middle
self.center_button = tk.Button(root, text="Click Me!", font=("Arial", 16),
command=self.center_button_click)
self.center_button.place(x=350, y=275) # Place the button in the center
(adjustable)
# Bind click event
self.canvas.bind("<Button-1>", self.click)
def click(self, event):
if self.pixels:
# Remove a random "pixel"
pixel = random.choice(self.pixels)
self.canvas.delete(pixel)
self.pixels.remove(pixel)
# Play the click sound
self.click_sound.play()
def center_button_click(self):
print("You clicked the center button!")
if __name__ == "__main__":
root = tk.Tk()
game = PixelDestroyerGame(root)
root.mainloop()