Jan-08-2019, 07:33 PM
Good day all,
It seems like the cleanest, easiest way for me to build a GUI is with PySimpleGui, and it's well underway, but I'm having some trouble getting mutliple buttons do run different functions. Hoping it's just a syntax problem, but thought I'd see if anybody here had a few minutes to help.
In a nutshell, I want to have 2 buttons
A) Check DB for SUID (which will run function 'checkdb()'
B) Submit (which will run function 'updatedb()'
I've cut out the middle portion of the code, and I know what's IN the functions needs some additional work, but here's what I have at the moment. I noted the two calls with *** since I can't get the bold to work here.
I *think* the "checkdb" call at the bottom will execute no matter what, but, as noted, I would like it tied to the SUBMIT button.
Thank you for any guidance!
It seems like the cleanest, easiest way for me to build a GUI is with PySimpleGui, and it's well underway, but I'm having some trouble getting mutliple buttons do run different functions. Hoping it's just a syntax problem, but thought I'd see if anybody here had a few minutes to help.
In a nutshell, I want to have 2 buttons
A) Check DB for SUID (which will run function 'checkdb()'
B) Submit (which will run function 'updatedb()'
I've cut out the middle portion of the code, and I know what's IN the functions needs some additional work, but here's what I have at the moment. I noted the two calls with *** since I can't get the bold to work here.
I *think* the "checkdb" call at the bottom will execute no matter what, but, as noted, I would like it tied to the SUBMIT button.
Thank you for any guidance!
import PySimpleGUI as sg import pyodbc import os def checkdb(): connstring = 'DRIVER={SQL Server};SERVER=myserver;DATABASE=mydatabase;UID=myuserid;PWD=mypassword' mysuid = "'" + values[0] +"'" SQLstr="select count(distinct(SUID)) from [DCollection].[dbo].[Contribs] where SUID =" + mysuid print(SQLstr) conn=pyodbc.connect(connstring) cursor=conn.cursor() cursor.execute(SQLstr) result = cursor.fetchone() sg.Popup('Instances in DB:', result[0]) def updatedb(): connstring = 'DRIVER={SQL Server};SERVER=myserver;DATABASE=mydatabase;UID=myuserid;PWD=mypassword' #mysuid = "'" + values[0] +"'" SQLstr="insert into [DCollection].[dbo].[Contribs] SUID =" + mysuid print(SQLstr) conn=pyodbc.connect(connstring) cursor=conn.cursor() cursor.execute(SQLstr) result = cursor.fetchall() for row in result: print (row[0]) sg.ChangeLookAndFeel('BlueMono') layout = [ [], [sg.Text('Please enter the appropriate judgements')], [sg.Text('SUID', size=(10, 1)), sg.InputText(size =(20,1)), sg.InputCombo(('Select Wire Code','19', '42', '51','59', '119', '168','178', '178', '193','327','934','2575','3459'), size=(20, 1)), sg.InputCombo(('Select Contributor','AGEIS', 'BANK OF AMERICA', 'BARCLAYS','CITIBANK', 'CREDIT SUISSE', 'DEUTSCHE BANK','EVERCORE ISI', 'GOLDMAN SACHS', 'GOLDMAN SACHS RD1','JP MORGAN','NOMURA','UBS','WELLS FARGO'), size=(30, 1))], **** [sg.Button('Check DB for SUID')], **** [sg.Text('NI Code 1', size=(10, 1)), sg.InputText(size=(20,1)), sg.InputCombo(('Select Category','ACTION', 'ANALYST', 'INDUSTRY','RATING', 'SETFOCUS', 'TICKER'), size=(20, 1)), sg.InputCombo(('Select Judgement','CORRECTLY ASSIGNED', 'CORRECTLY DERIVED','INCORRECTLY ASSIGNED','INCORRECTLY DERIVED','NOT ASSIGNED','NOT DERIVED','BIO-NO PPLM','NO BIO ON TERMINAL'), size=(30, 1)),sg.Text('NOTES', size=(6, 1)), sg.InputText(size =(60,1))], [sg.Text('NI Code 2', size=(10, 1)), sg.InputText(size=(20,1)), sg.InputCombo(('Select Category','ACTION', 'ANALYST', 'INDUSTRY','RATING', 'SETFOCUS', 'TICKER'), size=(20, 1)), sg.InputCombo(('Select Judgement','CORRECTLY ASSIGNED', 'CORRECTLY DERIVED','INCORRECTLY ASSIGNED','INCORRECTLY DERIVED','NOT ASSIGNED','NOT DERIVED','BIO-NO PPLM','NO BIO ON TERMINAL'), size=(30, 1)),sg.Text('NOTES', size=(6, 1)), sg.InputText(size =(60,1))], [sg.Text('USER: ' + os.getlogin(),font='Helvetica 12 bold')], [sg.Submit(), sg.Cancel()] ] window = sg.Window('Contributor Analysis Input').Layout(layout) event, values = window.Read() *** checkdb()*** window.Close()