-1
import threading
from PySimpleGUI import PySimpleGUI as sg

    def thread2():
        while (x == True):
            if values["radio"] == True:
                print("true")
    
    
    def thread1():
    
    
        tab1_layout =  [              
                [sg.Radio('G', "RADIO1", default=True, size=(10,1), key='radio'), sg.Radio('R', "RADIO1")]
                ] 
    
                  (...)
    
        while True:
            
            events, values = janela.read()
                    
    threading.Thread(target=thread1).start()  
    sleep(5)
    threading.Thread(target=thread12).start()        
    

My code is something like that How can I acess user values option of the radio using Multithreaded and pysimplegui?

error: name 'values' is not defined

diegooli
  • 123
  • 2
  • 11
  • You can pass arguments, like `values`, by `threading.Thread(target=thread1, args=(values, )).start()`, or use global variable, or attribute of instance of class. – Jason Yang Dec 15 '21 at 17:02
  • Not a python expert here, but could the problem be the use of two similar but different identifiers? In thread2 you test an identifier named valores while in thread1 you modify an identifier named values. – Jim Rogers Dec 15 '21 at 18:05
  • @JasonYang File "C:\Users\noname\Desktop\code\OCR\ocr2.py", line 421, in threading.Thread(target=thread12, args=(values, )).start() NameError: name 'values' is not defined it's like this variable was never defined, even if i enter global i can't access it – diegooli Dec 15 '21 at 19:48
  • @JimRogers I fixed it, it was an error when transcribing to stackoverflow – diegooli Dec 15 '21 at 19:49

1 Answers1

0

It looks that the structure of your script is something wrong, the GUI part should be under main thread.

import threading
import PySimpleGUI as sg

def thread(window, values):

    ...

    while (x == True):

        if values["radio"]:
            print("true")

    ...

def main():

    tab1_layout =  [
            [sg.Radio('G', "RADIO1", default=True, size=(10,1), key='radio'), sg.Radio('R', "RADIO1")]
            [sg.Button('Submit')],
    ]

    ...

    while True:

        event, values = janela.read()

        if event == sg.WINDOW_CLOSED:
            break
        elif event == 'Submit':
            threading.Thread(target=thread, args=(window, values), daemon=True).start()

    window.close()

main()
Jason Yang
  • 11,284
  • 2
  • 9
  • 23