Product registration using Pysimplegui and Python

Asked

Viewed 435 times

-1

I’d like some help.

I’m training in this code:

    categoria = ['Celular', 'Bateria', 'Carregador']
    marca = ['Iphone', 'Motorola', 'LG']
    cor = ['Branco', 'Verde', 'Preto']
    fonte = 20

    layout = [[sg.Text('Código', font=fonte), sg.Input(key='-COD-', font=fonte, size=(20, 1))],
      [sg.Text('Unidade', font=fonte), sg.InputText(key='-UNID-', font=fonte, size=(10, 1))],
      [sg.Text('Nome', font=fonte), sg.Input(key='-NOME-', size=(30, 1))],
      [sg.Text('Categoria', font=fonte), sg.Combo(categoria, font=fonte, key='-CATEG-', size=(30, 1))],
      [sg.Text('Marca', font=fonte), sg.Combo(marca, font=fonte, key='-MARCA-')],
      [sg.Text('Cor/Estampa', font=fonte), sg.Combo(cor, font=fonte, key='-COR-')],
      [sg.Text('')],
      [sg.Button('Cadastrar', font=fonte), sg.Button('Cancelar', font=fonte)]]

    window = sg.Window('CADASTRO DE PRODUTOS', layout, size=(700, 300))

    while True:
        event, values = window.read()
        if event in (sg.WIN_CLOSED, 'Cancelar'):
            break
        if event == 'Cadastrar':
            window['-NOME-'].update(window['-CATEG-'])


    window.close()

I would like the value chosen in the Combo whose key='-CATEG-' was filled in key= '-NAME-'. But it is returning the object and not the chosen value, type the following: <Pysimplegui.PySimpleGUI.Combo Object at 0x7fd8bf982a60>.

And another thing: You can concatenate the key: '-CATEG-' + '-MARCA-' + '-COR-' and this junction is placed in key='-NAME-'?. Example: In Combo 'Category' was chosen the option Cellular; in 'Brand, Motorola and 'Color', Black. Thus, the field 'Name' should be: Motorola Black Cell Phone.

Also, is it good practice to create variables to define some parameters, as I did in the case of the source? I thought so because I believe it will be easier to perform maintenance.

1 answer

0

For this to happen you have to set the variable of the Key, as follows:

-CATEG- = values['-CATEG-']

To transform the '-CATEG-' value into 'NAME'

_CATEG_ = values['-CATEG-']
_NOME_  = values['_CATEG_']

This way the value becomes a variable and can also be concatenated.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.