This is my code:
import PySimpleGUI as sg
import datetime
from datetime import date
import pandas as pd
columns = ["TYPE","DIRECTION","DATE","OPTION"]
param = (20,3) # size of the main window
def GUI():
sg.theme('Dark Brown 1')
listing = [sg.Text(u, size = param) for u in columns]
core = [
sg.Input(size = param),
sg.Input(size = param),
sg.Input(size = param),
sg.Input(size = param)]
mesh = [[x,y] for (x,y) in list(zip(listing, core))]
layout =[[sg.Button("SEND")]]+ mesh
window = sg.Window('Trade Entry System', layout, font='Courier 12').Finalize()
while True:
event, values = window.read()
if event == "SEND":
data = values
a = list(data.values())
df = pd.DataFrame(a, index = columns)
df = df.transpose()
print(df)
else:
print("OVER")
break
window.close()
GUI()
What i want to do is for example if the string 'STOCK' is inputted into the TYPE input then the remaining 3 input boxes should be filled with predefined values. For example DIRECTION filled with 'B', Date with 'TODAY' and OPTION with 'PUT'.
I am unsure how to start so any help would be great
Set option enable_events=True
in your TYPE
input, it will generate events when the content of element changed, then handle it in your event loop if the content of element equal 'STOCK'
.
import datetime
from datetime import date
import pandas as pd
import PySimpleGUI as sg
def GUI():
columns = ["TYPE","DIRECTION","DATE","OPTION"]
param = (20,3) # size of the main window
sg.theme('Dark Brown 1')
sg.set_options(font=('Courier New', 12))
listing = [sg.Text(u, size = param) for u in columns]
core = [
sg.Input(size=param, enable_events=True, key='INPUT TYPE'),
sg.Input(size=param),
sg.Input(size=param),
sg.Input(size=param),
]
mesh = [[x,y] for (x,y) in list(zip(listing, core))]
layout = [[sg.Button("SEND")]] + mesh
window = sg.Window('Trade Entry System', layout, finalize=True)
while True:
event, values = window.read()
if event == sg.WINDOW_CLOSED:
break
elif event == "INPUT TYPE" and values[event] == "STOCK":
for element, value in zip(core[1:], ['B', 'TODAY', 'PUT']):
element.update(value=value)
window.close()
GUI()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.