-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmach.py
61 lines (47 loc) · 1.49 KB
/
mach.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
import tkinter as tk
win = tk.Tk() # win equals to a tkinter window
HEIGHT = 600
WIDTH = 480
win.title("MACH") # window title
win.geometry(f'{HEIGHT}x{WIDTH}')
# label = tk.Label(text="Borealis Mission Control!")
# data = tk.StringVar()
# data.set("hello")
# label2 = tk.Label(textvariable=data)
#buttons
# def launch_rocket(): # callback to run when btn clicked
# print("🚀🚀🚀")
# def abort():
# print("💥💥💥💥")
state = tk.StringVar()
state.set("Close")
button = tk.Button(text="Launch", command=lambda: state.set("Open"))
abortbtn= tk.Button(text="ABORT", command=lambda: state.set("Close"), foreground="#FF0000")
## COMMUNICATION CODE
import socket, time
HOST = "127.0.0.1"
PORT = 65431 # Port to listen on (non-privileged ports are > 1023)
# label.pack()
# label2.pack()
button.pack()
abortbtn.pack()
# def receieve_data():
# received = conn.recv(1024)
# # all widgets to be packed to see on the window
# data.set(received.decode('utf-8'))
# print(received.decode('utf-8'))
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print(f"Connected by {addr}")
conn.send(b"Welcome to Borealis Mission Control")
# s.recv()
while True:
# num = input("enter a number: ")
conn.send(bytes(state.get(), 'utf-8'))
time.sleep(1)
win.update()
# while True:
# receieve_data()