-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflipper.py
More file actions
26 lines (18 loc) · 887 Bytes
/
flipper.py
File metadata and controls
26 lines (18 loc) · 887 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import tkinter as tk
import random
root = tk.Tk()
root.title("My color flipper")
root.geometry("400x300")
# Create a label for your window
label = tk.Label(root, text = "Click the button to flip color", font=("Arial", 16))
label.pack(pady = 30) #pack places the label in the window and paddy adds vertical space
colors = ["green","gold","lime","yellow","cyan","magenta","pink", "red", "white","purple", "blue", "green", "orange"]
def flip_color():
color = random.choice(colors) #picks a random color from the list
#change the background to the color of "color"
root.configure(bg =color)
label.config(text = f"Current color: {color}") #update the text to show the name of the color
button.config(bg =color)
button = tk.Button(root, text = "Flip Color", font=("Arial", 14), command = flip_color)
button.pack(pady=20) #for vertical spacing again
root.mainloop()