I am trying to make (what I thought) would be fairly simple GUI with a lighting control switch. I am using Pythonista on iOS. It's not actually controlling a light. I just want something that prints to the console that the switch is on or off. I'm extremely new to coding, and just can't figure it out. When I run the code the GUI will appear and print the state of the switch (upon loading) but it will not print if the switch is used after that.
#Lighting Control Switch
import ui
def lightControl(mySwitch):
toggle.switch1 = mySwitch
switch1 = "Off" or "On"
action_On = False
print(not action_On)
action_Off = (not action_On)
print(action_On)
if action_On == True:
print("Lights On")
if action_Off == True:
print("Lights Off")
v = ui.load_view()
v.present('sheet')
I want a switch that indicates to the console that it has been used and whether it is currently on or off.
No errors are printing and the GUI comes up as it should. Just not the result I want.
I'm very new to coding and just trying to learn and figure things out.
Since I was testing without making a .pyui file (the file where you edit the actual GUI layout) I had to remove
ui.loadview()
. But this works and should give you a good starting point. The Pythonista UI Module can be tricky, but sticking with it is worth it :)Also @Lukas is right, the Pythonista Forum is a great place to get help when you’re stuck.