0% found this document useful (0 votes)
8 views1 page

Doowap Shoowap

The document describes a Python program that creates a simple game using Tkinter and Pygame. In the game, users can click on a canvas filled with green rectangles (simulating pixels) to remove them randomly, while a button in the center allows for additional interaction. The program also includes sound effects for clicks, enhancing the user experience.

Uploaded by

astboutwood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Doowap Shoowap

The document describes a Python program that creates a simple game using Tkinter and Pygame. In the game, users can click on a canvas filled with green rectangles (simulating pixels) to remove them randomly, while a button in the center allows for additional interaction. The program also includes sound effects for clicks, enhancing the user experience.

Uploaded by

astboutwood
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

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

You might also like