-
Notifications
You must be signed in to change notification settings - Fork 345
/
flip.py
44 lines (33 loc) · 859 Bytes
/
flip.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from tkinter import *
root = Tk()
root.title('Codemy.com - Flip The Switch!')
root.iconbitmap('c:/gui/codemy.ico')
root.geometry("500x300")
# Keep track of the button state on/off
#global is_on
is_on = True
# Create Label
my_label = Label(root,
text="The Switch Is On!",
fg="green",
font=("Helvetica", 32))
my_label.pack(pady=20)
# Define our switch function
def switch():
global is_on
# Determin is on or off
if is_on:
on_button.config(image=off)
my_label.config(text="The Switch is Off", fg="grey")
is_on = False
else:
on_button.config(image=on)
my_label.config(text="The Switch is On", fg="green")
is_on = True
# Define Our Images
on = PhotoImage(file="images/on.png")
off = PhotoImage(file="images/off.png")
# Create A Button
on_button = Button(root, image=on, bd=0, command=switch)
on_button.pack(pady=50)
root.mainloop()