0

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

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.