Skip to content

Instantly share code, notes, and snippets.

@JeffersGlass
Created November 9, 2020 00:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save JeffersGlass/50ba8c7f8a9315a1b13162ba5390f0ff to your computer and use it in GitHub Desktop.
import tkinter as tk
from functools import partial
import tkinter.font as tkfont
from gpiozero import LED
class App(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.redLed = LED(26)
self.yellowLed = LED(19)
self.greenLed = LED(13)
self.allOff()
self.basicFont = tkfont.Font(family='Lucida Grande', size=30)
self.topLabel = tk.Label(self, text="Set Color", font=self.basicFont)
self.topLabel.grid(row=0, column=0)
self.redButton=tk.Button(self, text='RED', bg="#FFAAAA", font=self.basicFont, command=partial(self.buttonPress, 'red'))
self.redButton.grid(row=1, column=0)
self.yellowButton=tk.Button(self, text='YELLOW', bg="#FFFFAA", font=self.basicFont, command=partial(self.buttonPress, 'yellow'))
self.yellowButton.grid(row=2, column=0)
self.greenButton=tk.Button(self, text='GREEN', bg="#AAFFAA", font=self.basicFont, command=partial(self.buttonPress, 'green'))
self.greenButton.grid(row=3, column=0)
self.offButton=tk.Button(self, text='OFF', bg="#CCCCCC", font=self.basicFont, command=self.allOff)
self.offButton.pack()
self.pack(fill=tk.BOTH, expand=1)
def buttonPress(self, color):
self.allOff()
if color == 'red':
self.config(bg="#FF7777")
self.redLed.on()
elif color == 'yellow':
self.config(bg="#FFFF77")
self.yellowLed.on()
elif color == 'green':
self.config(bg="#77FF77")
self.greenLed.on()
def allOff(self):
self.redLed.off()
self.yellowLed.off()
self.greenLed.off()
if __name__ == '__main__':
myApp = App(tk.Tk())
myApp.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment