How to initialize a variable only one time when program starts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vehi
    New Member
    • Sep 2013
    • 2

    How to initialize a variable only one time when program starts

    For example I have a button and I would like to use it to turn something on and off with the same button.
    So I thougt, I would use some wariable which woild keep track of the state, but I can't seem to make it work.
    I would need to initialize X to value 0, but that initialization should happen only once when the program starts.

    x = 0 -> (this part should happen only when program is started)

    if x == 0:
    turn switch on
    x = 1
    else:
    turn switch off
    x = 0
  • vehi
    New Member
    • Sep 2013
    • 2

    #2
    I found another solution.
    I used a ToggleButton and .get_active() method
    to get the state of a button.

    Comment

    Working...