-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui.py
48 lines (35 loc) · 1.39 KB
/
gui.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
# gui.py
# Displays a tkinter GUI wih buttons which trigger Events to Microsoft Flight Simulator S2020 via Python-SimConnect
from tkinter import *
from SimConnect import * #Requires Python-SimConnect from https://pypi.org/project/SimConnect/ (pip install SimConnect)
# Create connection to Sim
sm = SimConnect()
ae = AircraftEvents(sm)
aq = AircraftRequests(sm, _time=2000)
def trigger_event(event_name, value_to_use = None):
#This is where the event is triggered to SimConnect
event_to_trigger = ae.find(event_name)
if event_to_trigger is not None:
if value_to_use is None:
event_to_trigger()
else:
event_to_trigger(int(value_to_use))
status = "success"
else:
status = "Error: %s is not an Event" % (event_name)
return status
#Trigger the event
#trigger_event("PITOT_HEAT_TOGGLE")
#Set up the window
gui = Tk()
gui.title("FS2020-HWPanel - UI Test")
gui.geometry("500x200")
#Add buttons
Button(gui, text="PITOT HEAT", width = 15, command=lambda: trigger_event("PITOT_HEAT_TOGGLE")) .grid(row=0, column=0, sticky=W)
Button(gui, text="FUEL PUMP", width = 15, command=lambda: trigger_event("FUEL_PUMP")) .grid(row=0, column=1, sticky=W)
Button(gui, text="LANDING LIGHTS", width = 15, command=lambda: trigger_event("LANDING_LIGHTS_TOGGLE")) .grid(row=0, column=2, sticky=W)
#loop
gui.mainloop()
# Disconnect and exit
sm.exit()
exit()