Criando Tela com PySimpleGUI

Desafio da aula 01 onde precisamos criar uma tela usando o PySimpleGUI para cadastrar uma pessoa
 avatar
Rantro0177
python
6 months ago
728 B
3
Indexable
import PySimpleGUI as sg

# Tema
sg.theme('DarkGrey10')
# Layout
layout = [
    [sg.Text('Digite seu nome:')],
    [sg.Input(key='nome')],
    [sg.Text('Digite sua idade:')],
    [sg.Input(key='idade')],
    [sg.Button(button_text = 'Ok')]
]
# Janela
window = sg.Window('Tela de Cadastro', layout=layout)
#Leitura e eventos de valores
while True:
    event,values = window.read()
#ler e reagir aos eventos
    if event == sg.WIN_CLOSED:
        break
    elif event == 'Ok':
        print('Você clicou ok')
        nome = values['nome']
        idade = values['idade']
        if nome and idade == None:
            print('Precisa preencher os campos!')
        else:
            print(f'O {nome} tem {idade} anos de idade:')  
Editor is loading...
Leave a Comment