-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMqttRobot.py
66 lines (50 loc) · 1.58 KB
/
MqttRobot.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
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
from Tkinter import *
import os
def hello(e):
print('hello world!')
def bye(e):
print('bye world!')
def move(e):
print('move!')
os.system("mosquitto_pub -q 2 -t play -m move")
def back(e):
print('back!')
os.system("mosquitto_pub -q 2 -t play -m back")
def left(e):
print('left!')
os.system("mosquitto_pub -q 2 -t play -m left")
def right(e):
print('right!')
os.system("mosquitto_pub -q 2 -t play -m right")
def stop(e):
print('stop!')
os.system("mosquitto_pub -q 2 -t play -m stop")
def test():
print('test!')
os.system("mosquitto_pub -q 2 -t play -m test")
win = Tk()
win.title('MQTT Robot')
win.geometry('400x200')
#btnHello = Button(win, text='Click me')
#btnHello.bind("<Button-1>", hello)
#btnHello.bind("<ButtonRelease-1>", bye)
#btnHello.pack(expand=YES, fill=BOTH)
btnMove = Button(win, text='Move')
btnMove.bind("<Button-1>", move)
btnMove.bind("<ButtonRelease-1>", stop)
btnMove.pack(side=TOP, expand=YES)
btnBack = Button(win, text='Back')
btnBack.bind("<Button-1>", back)
btnBack.bind("<ButtonRelease-1>", stop)
btnBack.pack(side=BOTTOM, expand=YES)
btnLeft = Button(win, text='Left')
btnLeft.bind("<Button-1>", left)
btnLeft.bind("<ButtonRelease-1>", stop)
btnLeft.pack(side=LEFT, expand=YES)
btnTest = Button(win, text='Test', command=test)
btnTest.pack(side=LEFT, expand=YES, fill=BOTH)
btnRight = Button(win, text='Right')
btnRight.bind("<Button-1>", right)
btnRight.bind("<ButtonRelease-1>", stop)
btnRight.pack(side=RIGHT, expand=YES)
mainloop()