-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtkinter_led.py
36 lines (29 loc) · 852 Bytes
/
tkinter_led.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
from pyfirmata import Arduino, util
from tkinter import *
board = Arduino("COM4")
it = util.Iterator(board)
it.start()
led = board.get_pin("d:13:o")
m = Tk()
def led_on():
while True:
led.write(1)
refresh(m)#this causes a problem which can removed by removing 'm'
#but then the window will close after one click
def led_off():
while True:
led.write(0)
refresh(m)
m.title("GUI + Arduino")
m.geometry("100x100")#pady for grid and themes for tkinter. To get themes pip install ttkthemes
thelabel = Label(m, text = "Welcome to led simulation!")
thelabel.pack(side = TOP)
btn1 = Button(m, text = "ON", command = led_on )
btn1.pack(side = LEFT)
btn2 = Button(m, text = "OFF", command = led_off)
btn2.pack(side = LEFT)
def refresh(window):
window.destroy()
window.__init__()
m.mainloop()
board.exit()