Skip to content

Instantly share code, notes, and snippets.

@kkm
Created April 18, 2020 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkm/ccc46c9b451e5bb5f6368dcc6bdb0d51 to your computer and use it in GitHub Desktop.
Save kkm/ccc46c9b451e5bb5f6368dcc6bdb0d51 to your computer and use it in GitHub Desktop.
GrowPiGui - raspberry touch
from Tkinter import *
import tkFont
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
cred = credentials.Certificate('serviceAccountKey.json')
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://growpi.firebaseio.com/'
})
ref = db.reference('grovepi/ultrasonic/live')
win = Tk()
# FULLSCREEN
# win.overrideredirect(True)
# win.overrideredirect(False)
# win.attributes('-fullscreen', True)
myFont = tkFont.Font(family='Helvetica', size=34, weight='bold')
myFont2 = tkFont.Font(family='Helvetica', size=18, weight='bold')
top = False
fan = False
def topToggle():
global top
if top == True:
db.reference("toggle").update({
'1-pin': False
})
print("TOP button pressed: OFF")
topButton["text"] = "TOP OFF"
topButton["fg"] = "RED"
topButton["activeforeground"] = "RED"
top = False
else:
db.reference("toggle").update({
'1-pin': True
})
print("TOP button pressed: ON")
top = True
topButton["text"] = "TOP ON"
topButton["fg"] = "GREEN"
topButton["activeforeground"] = "GREEN"
def fanToggle():
print("FAN button pressed")
global fan
if fan == True:
db.reference("toggle").update({
'15-pin': False
})
fanButton["text"] = "FAN OFF"
fanButton["fg"] = "RED"
fanButton["activeforeground"] = "RED"
fan = False
else:
db.reference("toggle").update({
'15-pin': True
})
fan = True
fanButton["text"] = "FAN ON"
fanButton["fg"] = "GREEN"
fanButton["activeforeground"] = "GREEN"
def exitProgram():
print("Exit Button pressed")
win.quit()
def on_enter(e):
topButton['background'] = 'green'
win.title("Grow-Relais")
win.geometry('800x480')
# EXIT
exitButton = Button(win, text="Exit", font=myFont2, command=exitProgram, width=5, bg="grey")
exitButton.pack(side=BOTTOM, pady=10)
# photo = PhotoImage(file="power.gif")
# topButton = Button(win, image=photo, text="TOP OFF", font=myFont, command=topToggle, fg="RED", bg="grey", height=200, width=250, compound=LEFT)
topButton = Button(win, text="TOP OFF", font=myFont, command=topToggle, fg="RED", bg="grey", height=3, activebackground="grey", activeforeground="RED")
topButton.pack(side=LEFT, padx=10)
fanButton = Button(win, text="FAN OFF", font=myFont, command=fanToggle, fg="RED", bg="grey", height=3, activebackground="grey", activeforeground="RED")
fanButton.pack(side=RIGHT, padx=10)
mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment