I am trying out pysimplegui to use it as a gui for others to run my code. I manage to create a 2 window gui where the 2nd window is for admin use. But i found that if i were to do a few times of entering and exiting windows 2, there will be an error.
Below is the code example where an error would occur. The 2nd window will popup when click on admin>Settings. Then if i were to exit and enter in a few more times (<4times) an error would occur. The error is:
File "<ipython-input-2-4e0963ff7cf8>", line 1, in <module>
runfile('C:/Python/test.py', wdir='C:/Python')
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
execfile(filename, namespace)
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "C:/Python/test.py", line 29, in <module>
(ev2, vals2) = win2.Read()
File "C:\ProgramData\Anaconda3\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 5284, in Read
self._Show()
File "C:\ProgramData\Anaconda3\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 5163, in _Show
return _BuildResults(self, False, self)
File "C:\ProgramData\Anaconda3\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 6754, in _BuildResults
_BuildResultsForSubform(form, initialize_only, top_level_form)
File "C:\ProgramData\Anaconda3\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 6843, in _BuildResultsForSubform
value = element.TKIntVar.get()
File "C:\ProgramData\Anaconda3\lib\tkinter\__init__.py", line 506, in get
value = self._tk.globalgetvar(self._name)
TclError: can't read "PY_VAR60": no such variable
Where the number "60" in "PY_VAR60" can change to any number.
import PySimpleGUI as sg
menu_def= [['&Admin',['&Settings','&About']]]
layout1=[
[sg.Menu(menu_def)],
[sg.Text('Input WaferID:', size=(12, 1), font=('Calibri',15))],
[sg.Button('Exit')]
]
layout2 = [
[sg.Checkbox('Rename file?',key='rename', size=(15,1)),sg.Text('Split:')],
[sg.InputText()],
[sg.Button('Exit')]
]
win1 = sg.Window('Oxidation Object Detection V1.0').Layout(layout1)
win2_active = False
while True:
(ev1, vals1) = win1.Read()
if ev1 == 'Settings':
win2_active = True
win2 = sg.Window('Settings').Layout(layout2)
while True:
(ev2, vals2) = win2.Read()
if ev2 == 'Exit' or ev2 == None:
win2.Close()
win2_active = False
break
elif ev1 == 'Exit' or ev1 == None:
win1.Close()
break
I have tried replacing the checkbox of window 2 with sg.InputText and there would be no error. Is there something i am miss when using checkbox? Thank you.