-1
Hello
I’m using pyqt5 to create the graphical interface of a supposed clothing store (I’m training), I have the fields to receive the data to register each type of clothing, but when clicking the sign up button it saves the correct data in the txt file, but when registering a second piece he registers twice the same thing, if he registers a third piece he registers 4 and so on, does anyone know what it might be? Code below.
from PyQt5 import uic,QtWidgets
def CadastrarProdutos():
cadastrar.show()
description = cadastrar.lineEdit.text()
price = cadastrar.lineEdit_2.text()
amount = cadastrar.lineEdit_3.text()
dados = description, price, amount
cadastrar.pushButton.clicked.connect(SalvarDados_cadastro)
return dados
def SalvarDados_cadastro():
dados_save = CadastrarProdutos()
print(dados_save)
db = open("Estoque.txt","a+")
dados_formatados = ("|".join(dados_save)) + "\n"
db.write(dados_formatados)
db.close()
try:
with open('Estoque.txt', 'r') as f:
pass
except IOError:
create_db = open("Estoque.txt","a+")
create_db.write("Descricao|Preco|Quantidade\n")
create_db.close()
app=QtWidgets.QApplication([])
menu=uic.loadUi("menu_button.ui")
menu.pushButton.clicked.connect(CadastrarProdutos)
cadastrar=uic.loadUi("cadastro_button.ui")
menu.show()
app.exec()
The data is saved as shown below after I try to register the following items: T-shirt, pink T-shirt and short pink T-shirt with their respective values and quantities.
('Camiseta', '15', '10')
('Camiseta Rosa', '16', '4')
('Camiseta Rosa', '16', '4')
('Camiseta Rosa curta', '14', '26')
('Camiseta Rosa curta', '14', '26')
('Camiseta Rosa curta', '14', '26')
('Camiseta Rosa curta', '14', '26')
I need to store only 1 at a time, can anyone tell me where I’m going wrong? Thanks.
Important you [Dit] your question and explain objectively and punctually the difficulty found, accompanied by a [mcve] of the problem and attempt to solve. To better enjoy the site, understand and avoid closures and negativations worth reading What is the Stack Overflow and the Stack Overflow Survival Guide (summarized) in Portuguese.
– Bacco