forked from aditya-tiwari5258378/GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLED_ON_OFF.py
More file actions
84 lines (68 loc) · 2.74 KB
/
LED_ON_OFF.py
File metadata and controls
84 lines (68 loc) · 2.74 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from tkinter import *
import pymysql
import tkinter.messagebox as msg
root = Tk()
#root.state('normal')
root.geometry("600x400+300+100")
root['bg'] = 'yellow'
# def databaseConnection():
# global conn
# conn = pymysql.connect("localhost", "root", "", "python")
# msg.showinfo("Database", "Database connected successfully.")
def ledON():
conn = pymysql.connect("localhost", "root", "samyak@1997", "python")
cur = conn.cursor()
conf = msg.askyesno("Alert!!!", "Are you sure want to led ON ?")
if (conf):
cur.execute("UPDATE `iot` SET `status`='ON' WHERE id=100")
conn.commit()
bulb=PhotoImage(file="led_on.png")
l_img.config(image=bulb)
msg.showinfo("Database", "Database updated successfully.")
def ledOFF():
conn = pymysql.connect("localhost", "root", "samyak@1997", "python")
cur = conn.cursor()
conf = msg.askyesno("Alert!!!", "Are you sure want to led OFF ?")
if (conf):
cur.execute("UPDATE `iot` SET `status`='OFF' WHERE id=100")
conn.commit()
bulb=PhotoImage(file="led_off.png")
l_img.config(image=bulb)
msg.showinfo("Database", "Database updated successfully.")
def fanON():
conn = pymysql.connect("localhost", "root", "samyak@1997", "python")
cur = conn.cursor()
conf = msg.askyesno("Alert!!!", "Are you sure want to fan ON ?")
if (conf):
cur.execute("UPDATE `iot` SET `status`='ON' WHERE id=101")
conn.commit()
msg.showinfo("Database", "Database updated successfully.")
def fanOFF():
conn = pymysql.connect("localhost", "root", "samyak@1997", "python")
cur = conn.cursor()
conf = msg.askyesno("Alert!!!", "Are you sure want to fan OFF ?")
if (conf):
cur.execute("UPDATE `iot` SET `status`='OFF' WHERE id=101")
conn.commit()
msg.showinfo("Database", "Database updated successfully.")
conn = pymysql.connect("localhost", "root", "samyak@1997", "python")
cur = conn.cursor()
cur.execute("select status from iot where id=100")
data=cur.fetchone()
if(data[0]=='OFF'):
bulb=PhotoImage(file="led_off.png")
elif(data[0]=='ON'):
bulb=PhotoImage(file="led_on.png")
led = Frame(root, width=300, height=200)
led.place(x=200, y=100)
l_img=Label(led,image=bulb,width=120,height=140)
l_img.place(x=160,y=40)
Label(led, text="LED Panel", bg="blue").place(x=50, y=50)
Button(led, text="ON", bg="green", command=ledON).place(x=50, y=100)
Button(led, text="OFF", bg='red', command=ledOFF).place(x=100, y=100)
fan = Frame(root, width=300, height=200)
Label(fan, text="FAN Panel", bg="blue").place(x=100, y=50)
Button(fan, text="ON", bg="green",command=fanON).place(x=100, y=100)
Button(fan, text="OFF", bg='red',command=fanOFF).place(x=150, y=100)
fan.place(x=550, y=100)
root.mainloop()