'pysimplegui problem with running multiple scripts with different strings in Python
I'm having trouble trying to make pysimplegui work as I want. I would like to open the program, enter my information, run "Extract", let the script finish (it shows details in the output). Then on the same window, I would like to run another one using the same button "Extract" once the first script has finished running.
The best I can do is loop it and it opens a new window and closes the first. How do I get it to just stay open and allow me to do another search without closing when the script is finished?
In other words, I want to open 1 GUI window and run multiple scripts using different parameters "keywords" or start/end dates. One after the other.
guivalues = ['', '', '', "localhost", "root", 'PASSWORD', '', ''];
while True:
sg.theme('Dark2')
layout = [
[sg.Text('Enter multiple Keywords, comma to separate')],
[sg.Text('Keywords', size=(20, 1)), sg.InputText()],
[sg.Text('Start Date YYYY-MM-DD: ', size=(20, 1)), sg.InputText(guivalues[1])],
[sg.Text('End Date YYYY-MM-DD: ', size=(20, 1)), sg.InputText(guivalues[2])],
[sg.Text('Host (usually localhost): ', size=(20, 1)), sg.InputText(guivalues[3])],
[sg.Text('User (usually root): ', size=(20, 1)), sg.InputText(guivalues[4])],
[sg.Text('mySQL password: ', size=(20, 1)), sg.InputText(guivalues[5])],
[sg.Text('Database: ', size=(20, 1)), sg.InputText(guivalues[6])],
[sg.Text('Table: ', size=(20, 1)), sg.InputText(guivalues[7])],
[sg.Output(size=(70, 15))],
[sg.Button('Extract'), sg.Button('Close')]
]
window = sg.Window('Python to SQL', layout)
event, guivalues = window.read()
if event == 'Close':
break
window.Close()
if event == 'Extract':
XXX EXTRACTION CODE XXXXX
window.read()
window.Close()
ISSUE RESOLVED
sg.theme('Dark2')
layout = [
[sg.Text('Enter multiple Keywords, comma to separate')],
[sg.Button('Extract', bind_return_key=True ), sg.Button('Close')]
]
window = sg.Window('Python to SQL', layout)
while True:
event, guivalues = window.read()
if event in (None, 'Quit'):
break
if event == 'Close':
break
if event == 'Extract':
mydb = mysql.connector.connect(
The key is not looping the GUI window. Use the "While True" loop for the script doing the backend work. And within the while loop, you "read" the window for conditional "event" statements. THEN you put the conditionals within the loop. In other words
#GUI Stuff# then
While True: event, guivalues = window.read() then Conditionals
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
