Python Forum
trying to change variable value with a def
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to change variable value with a def
#11
I really like the Socratica Youtube videos, watched the series and found they helped with such things. Matches my sense of humor.
The one on classes is Socratica class video
Reply
#12
hi, I tried the classes by themselves and they operated fine, but now I want to add a GUI and a while loop to my code with 2 radio buttons. here is my code.

from time import sleep
from tkinter import *
from tkinter import ttk

root = Tk()
class LED:
    def __init__(self, ON, OFF, delay):
        self.ON = ON
        self.OFF = OFF
        self.delay = delay

    def LED_blink(self):
        print(self.ON)
        sleep(self.delay)
        print(self.OFF)
        sleep(self.delay)

label = ttk.Label(root, text='ON')
label.pack()

def ONOFF():
    while var == 1:
        Led.LED_blink()

def ONOFFSTOP():
    while var1 == 1:
        break

Led = LED('ON', "OFF", 1)

var = IntVar()
var1 = IntVar()
radio1 = ttk.Radiobutton(root, text = 'Start', variable = var, command = ONOFF, value = 1).pack()
radio2 = ttk.Radiobutton(root, text = 'Stop', variable = var1, command = ONOFFSTOP, value = 1).pack()

root.mainloop()
whenever I press the start button it does nothing and stays pressed. help appreciated.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how can a variable change if I haven't changed it? niminim 5 612 Apr-07-2021, 06:57 PM
Last Post: niminim
  Change variable value during a while loop? penahuse 2 809 Nov-15-2020, 11:53 PM
Last Post: penahuse
  Change variable in an outside file ebolisa 5 557 Nov-11-2020, 04:41 AM
Last Post: ebolisa
  Change name of variable samuelbachorik 2 619 Aug-10-2020, 02:34 PM
Last Post: deanhystad
  How to find and change variable values ​​in memory thiagoD 1 769 Jun-08-2020, 03:45 AM
Last Post: bowlofred
  Python - change variable type during program execution ple 1 792 Apr-12-2020, 08:43 AM
Last Post: buran
  change value of a global variable across all modules aster 5 2,063 Jan-01-2019, 06:42 PM
Last Post: aster
  How to change global variable in function? dan789 5 1,977 Nov-10-2018, 08:55 PM
Last Post: dan789
  Unwanted variable change in module dannyH 2 1,369 May-08-2018, 05:33 PM
Last Post: dannyH

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020