-2
I’m doing a program to present in the college project, but I’m doing it through the window method by pySimpleGUI, I wanted when the person typed in Sg. Input a quantity, that quantity was calculated times the price of the product that would be in the table, tried in the ways that I knew just didn’t work, wanted to try to do by database only that also not found a way to take the data to the database and then pull back to the program, someone could help me solve if please.
code:
import PySimpleGUI as sg
import sqlite3
banco =sqlite3.connect("variaveis.db")
#janela inicial
def janela_inicial():
sg.theme("Reddit")
layout =[
[sg.Button("Comprar")],
[sg.Button("Informações")],
[sg.Button("Sair")]
]
return sg.Window("Inicio", layout= layout, finalize= True)
#janela de compras
def janela_compras():
sg.theme("Reddit")
layout = [
[sg.Text("Produtos:"), sg.Text(" Quantidade:")],
[sg.Text("[1] - Maçã: R$0,75"), sg.Input(key= 'quantM', size= (20,1))],
[sg.Text("[2] - Feijão: R$5,00"), sg.Input(key= 'quantF', size= (20,1))],
[sg.Text("[3] - Arroz: R$3,00"), sg.Input(key= 'quantA', size= (20,1))],
[sg.Button("Voltar"), sg.Button("Finalizar compra")]
]
return sg.Window("Compras", layout= layout, finalize= True)
#janela de conta
def janela_conta():
sg.theme("Reddit")
layout = [
[sg.Text("===================")],
[sg.Text(" Nota")],
[sg.Text("===================")],
[sg.Text("Produto:"), sg.Text(" Total:")],
[sg.Text("Maçã: R$")],
[sg.Text("--------------------------------------")],
[sg.Text("Feijão: R$")],
[sg.Text("--------------------------------------")],
[sg.Text("Arroz: R$")],
[sg.Text("--------------------------------------")],
[sg.Text("Total: R$")],
[sg.Button("Voltar"), sg.Button("Finalizar compra")]
]
return sg.Window("Nota", layout= layout, finalize= True)
def janela_informacoes():
sg.theme("Reddit")
layout = [
[sg.Text("Nenhuma informação no momento!")],
[sg.Button('Voltar')]
]
return sg.Window("Nota", layout= layout, finalize= True)
#janelas iniciais
janela1, janela2, janela3, janela4 = janela_inicial(), None, None, None
#loop leitura de eventos
while True:
window, event, value = sg.read_all_windows()
#quando a janela for fechada
if window == janela1 and event == sg.WIN_CLOSED:
break
elif window == janela2 and event == sg.WIN_CLOSED:
break
elif window == janela3 and event == sg.WIN_CLOSED:
break
elif window == janela4 and event == sg.WIN_CLOSED:
break
#proxima janela compras
elif window == janela1 and event == 'Comprar':
janela2 = janela_compras()
janela1.hide()
#proxima janela informações
elif window == janela1 and event == 'Informações':
janela4 = janela_informacoes()
janela1.hide()
#proxiam janela conta
elif window == janela2 and event == 'Finalizar compra':
janela3 = janela_conta()
janela2.hide()
#voltar janela comprar para inicial
if window == janela2 and event == "Voltar":
janela2.hide()
janela1.un_hide()
#voltar janela informaçoes para inicial
if window == janela4 and event == "Voltar":
janela4.hide()
janela1.un_hide()
#janela fechar programa
if window == janela1 and event == "Sair":
break
#voltar janela conta para comprar
if window == janela3 and event == "Voltar":
janela3.hide()
janela2.un_hide()
#janela pop-up
elif window == janela3 and event == 'Finalizar compra':
sg.popup("Obrigado pela compra e volte sempre!")
'''
Thanks for the help, man !!
– Waichiro