from Tkinter import *
import ttk
import time
import RPi.GPIO as GPIO
import threading
import os
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
def init(root):
root.title("QUIZ Control & Indication Panel - Pi Zero")
def close_window():
root.after(0, root.destroy)
root = Tk()
content = ttk.Frame(root, padding=(5,5,5,5))
root.geometry('1026x250')
global c1, c2, c3, c4, c5
c1 = StringVar()
c2 = StringVar()
c3 = StringVar()
c4 = StringVar()
c5 = StringVar()
content.grid(column=0, row=0)
teama = ttk.Label(content, text=" TEAM A ", font=("Helvetica",32, "bold"), background=c2.get())
teamb = ttk.Label(content, text=" TEAM B ", font=("Helvetica",32, "bold"), background=c2.get())
teamc = ttk.Label(content, text=" TEAM C ", font=("Helvetica",32, "bold"), background=c2.get())
teamd = ttk.Label(content, text=" TEAM D ", font=("Helvetica",32, "bold"), background=c2.get())
teama.grid(column=1, row=1, pady=10, padx=20)
teamb.grid(column=2, row=1, padx=20)
teamc.grid(column=3, row=1, padx=20)
teamd.grid(column=4, row=1, padx=20)
label_1 = ttk.Label(content, text="")
label_1.grid(column=1, row=0, pady=20)
label_2 = ttk.Label(content, text="")
label_2.grid(column=1, row=3)
label_3 = ttk.Label(content, text="")
label_3.grid(column=1, row=4)
label_4 = ttk.Label(content, text="")
label_4.grid(column=1, row=5)
label_5 = ttk.Label(content, text="")
label_5.grid(column=1, row=6)
label_6 = ttk.Label(content, text="")
label_6.grid(column=1, row=7)
label_7 = ttk.Label(content, text="walkerworks 2017", foreground="blue")
label_7.grid(column=4, row=8)
close = ttk.Button(content, command=close_window, text="Close")
close.grid(column=1, row=8)
GPIO.setup(17, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(27, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(22, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(6, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(13, GPIO.IN, pull_up_down = GPIO.PUD_UP)
led_blue = 18
led_yellow = 23
led_red = 24
led_green = 25
buzzer = 12
GPIO.setup(led_blue,GPIO.OUT)
GPIO.setup(led_yellow,GPIO.OUT)
GPIO.setup(led_red,GPIO.OUT)
GPIO.setup(led_green,GPIO.OUT)
GPIO.setup(buzzer,GPIO.OUT)
GPIO.output(led_blue,GPIO.HIGH)
GPIO.output(led_yellow,GPIO.HIGH)
GPIO.output(led_red,GPIO.HIGH)
GPIO.output(led_green,GPIO.HIGH)
GPIO.output(buzzer,GPIO.LOW)
def reset():
GPIO.output(led_blue,GPIO.HIGH)
GPIO.output(led_yellow,GPIO.HIGH)
GPIO.output(led_red,GPIO.HIGH)
GPIO.output(led_green,GPIO.HIGH)
c5.set("gray84")
teama.configure(background=c5.get())
teamb.configure(background=c5.get())
teamc.configure(background=c5.get())
teamd.configure(background=c5.get())
def A():
GPIO.output(led_blue,GPIO.LOW)
GPIO.output(buzzer,GPIO.HIGH)
c1.set("blue")
teama.configure(background=c1.get())
time.sleep(0.5)
GPIO.output(buzzer,GPIO.LOW)
while True:
time.sleep(0.05)
if GPIO.input(6)==0:
reset()
break
def B():
GPIO.output(led_yellow,GPIO.LOW)
GPIO.output(buzzer,GPIO.HIGH)
c2.set("yellow")
teamb.configure(background=c2.get())
time.sleep(0.5)
GPIO.output(buzzer,GPIO.LOW)
while True:
time.sleep(0.05)
if GPIO.input(6)==0:
reset()
break
def C():
GPIO.output(led_red,GPIO.LOW)
GPIO.output(buzzer,GPIO.HIGH)
c3.set("red")
teamc.configure(background=c3.get())
time.sleep(0.5)
GPIO.output(buzzer,GPIO.LOW)
while True:
time.sleep(0.05)
if GPIO.input(6)==0:
reset()
break
def D():
GPIO.output(led_green,GPIO.LOW)
GPIO.output(buzzer,GPIO.HIGH)
c4.set("green")
teamd.configure(background=c4.get())
time.sleep(0.5)
GPIO.output(buzzer,GPIO.LOW)
while True:
time.sleep(0.05)
if GPIO.input(6)==0:
reset()
break
def keys():
while True:
if GPIO.input(17)==0:
A()
if GPIO.input(27)==0:
B()
if GPIO.input(22)==0:
C()
if GPIO.input(5)==0:
D()
time.sleep(0.05)
def shutdown(shutdown):
os.system("sudo poweroff")
GPIO.add_event_detect(13, GPIO.FALLING, bouncetime=500, callback=shutdown)
t = threading.Thread(target=keys)
t.daemon=True
t.start()
init(root)
root.mainloop()