May-21-2022, 08:09 PM
Hello,
I'm trying to make a sellPrice variable that takes in the user's input from the Price Input that I have and multiplies 1.10 to it.
This is a snippet of my PriceInput:
Thanks in advance.
This is my full code:
I'm trying to make a sellPrice variable that takes in the user's input from the Price Input that I have and multiplies 1.10 to it.
This is a snippet of my PriceInput:
self.PriceInput = QtWidgets.QDoubleSpinBox(self.centralwidget) self.PriceInput.setStyleSheet("background-color: rgb(255, 255, 255);") self.PriceInput.setObjectName("PriceInput") self.formLayout_2.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.PriceInput)And these are the variables I have that store the user's input:
#Store the user's inputs ItemName = self.NameInput.text() Quantity = self.QuantityInput.text() Price = self.PriceInput.text() Description = self.DescriptionInput.toPlainText() Category = self.CategoryInput.currentText() Location = self.LocationInput.text() Barcode = self.BarcodeInput.text() Length = self.spinBox.value() sellPrice = Price * 1.10 mylist = [ItemName, Quantity, Price, sellPrice, Description, Category, Location, Length, Barcode]If I try to run my code:
Error: sellPrice = Price * 1.10
TypeError: can't multiply sequence by non-int of type 'float'
How do I fix this?Thanks in advance.
This is my full code:
from PyQt5 import QtCore, QtGui, QtWidgets import sqlite3 class Ui_AddItemMenu(QtWidgets.QMainWindow): def __init__(self, parent = None): super(Ui_AddItemMenu, self).__init__(parent) self.setObjectName("AddItemMenu") self.resize(804, 638) self.setStyleSheet("background-color: rgb(0, 170, 255);") self.centralwidget = QtWidgets.QWidget() self.centralwidget.setObjectName("centralwidget") self.formLayout_2 = QtWidgets.QFormLayout(self.centralwidget) self.formLayout_2.setObjectName("formLayout_2") self.AddItemTitle = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(15) font.setBold(True) font.setWeight(75) self.AddItemTitle.setFont(font) self.AddItemTitle.setAlignment(QtCore.Qt.AlignCenter) self.AddItemTitle.setObjectName("AddItemTitle") self.formLayout_2.setWidget(0, QtWidgets.QFormLayout.SpanningRole, self.AddItemTitle) self.NameLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.NameLabel.setFont(font) self.NameLabel.setObjectName("NameLabel") self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.NameLabel) self.NameInput = QtWidgets.QLineEdit(self.centralwidget) self.NameInput.setStyleSheet("background-color: rgb(255, 255, 255);") self.NameInput.setText("") self.NameInput.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) self.NameInput.setObjectName("NameInput") self.formLayout_2.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.NameInput) spacerItem = QtWidgets.QSpacerItem(0, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.formLayout_2.setItem(2, QtWidgets.QFormLayout.SpanningRole, spacerItem) self.QuantityLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.QuantityLabel.setFont(font) self.QuantityLabel.setObjectName("QuantityLabel") self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.QuantityLabel) self.QuantityInput = QtWidgets.QSpinBox(self.centralwidget) self.QuantityInput.setStyleSheet("background-color: rgb(255, 255, 255);") self.QuantityInput.setObjectName("QuantityInput") self.formLayout_2.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.QuantityInput) spacerItem1 = QtWidgets.QSpacerItem(0, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.formLayout_2.setItem(4, QtWidgets.QFormLayout.FieldRole, spacerItem1) self.PriceLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.PriceLabel.setFont(font) self.PriceLabel.setObjectName("PriceLabel") self.formLayout_2.setWidget(5, QtWidgets.QFormLayout.LabelRole, self.PriceLabel) self.PriceInput = QtWidgets.QDoubleSpinBox(self.centralwidget) self.PriceInput.setStyleSheet("background-color: rgb(255, 255, 255);") self.PriceInput.setObjectName("PriceInput") self.formLayout_2.setWidget(5, QtWidgets.QFormLayout.FieldRole, self.PriceInput) spacerItem2 = QtWidgets.QSpacerItem(20, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.formLayout_2.setItem(6, QtWidgets.QFormLayout.FieldRole, spacerItem2) self.DescriptionLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.DescriptionLabel.setFont(font) self.DescriptionLabel.setObjectName("DescriptionLabel") self.formLayout_2.setWidget(7, QtWidgets.QFormLayout.LabelRole, self.DescriptionLabel) self.DescriptionInput = QtWidgets.QPlainTextEdit(self.centralwidget) self.DescriptionInput.setStyleSheet("background-color: rgb(255, 255, 255);") self.DescriptionInput.setObjectName("DescriptionInput") self.formLayout_2.setWidget(7, QtWidgets.QFormLayout.FieldRole, self.DescriptionInput) self.CategoryLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.CategoryLabel.setFont(font) self.CategoryLabel.setObjectName("CategoryLabel") self.formLayout_2.setWidget(8, QtWidgets.QFormLayout.LabelRole, self.CategoryLabel) self.CategoryInput = QtWidgets.QComboBox(self.centralwidget) self.CategoryInput.setStyleSheet("background-color: rgb(225, 225, 225);") self.CategoryInput.setObjectName("CategoryInput") self.formLayout_2.setWidget(8, QtWidgets.QFormLayout.FieldRole, self.CategoryInput) spacerItem3 = QtWidgets.QSpacerItem(20, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.formLayout_2.setItem(9, QtWidgets.QFormLayout.FieldRole, spacerItem3) self.LocationLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.LocationLabel.setFont(font) self.LocationLabel.setObjectName("LocationLabel") self.formLayout_2.setWidget(10, QtWidgets.QFormLayout.LabelRole, self.LocationLabel) self.LocationInput = QtWidgets.QLineEdit(self.centralwidget) self.LocationInput.setStyleSheet("background-color: rgb(255, 255, 255);") self.LocationInput.setObjectName("LocationInput") self.formLayout_2.setWidget(10, QtWidgets.QFormLayout.FieldRole, self.LocationInput) spacerItem4 = QtWidgets.QSpacerItem(20, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.formLayout_2.setItem(11, QtWidgets.QFormLayout.FieldRole, spacerItem4) self.BarcodeLabel = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.BarcodeLabel.setFont(font) self.BarcodeLabel.setObjectName("BarcodeLabel") self.formLayout_2.setWidget(12, QtWidgets.QFormLayout.LabelRole, self.BarcodeLabel) self.BarcodeInput = QtWidgets.QLineEdit(self.centralwidget) self.BarcodeInput.setStyleSheet("background-color: rgb(255, 255, 255);") self.BarcodeInput.setObjectName("BarcodeInput") self.formLayout_2.setWidget(12, QtWidgets.QFormLayout.FieldRole, self.BarcodeInput) spacerItem5 = QtWidgets.QSpacerItem(0, 5, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.formLayout_2.setItem(14, QtWidgets.QFormLayout.FieldRole, spacerItem5) self.label = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.label.setFont(font) self.label.setObjectName("label") self.formLayout_2.setWidget(15, QtWidgets.QFormLayout.LabelRole, self.label) self.spinBox = QtWidgets.QSpinBox(self.centralwidget) self.spinBox.setStyleSheet("background-color: rgb(255, 255, 255);") self.spinBox.setObjectName("spinBox") self.formLayout_2.setWidget(15, QtWidgets.QFormLayout.FieldRole, self.spinBox) self.label_2 = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setBold(False) font.setItalic(True) font.setWeight(50) self.label_2.setFont(font) self.label_2.setAlignment(QtCore.Qt.AlignLeading|QtCore.Qt.AlignLeft|QtCore.Qt.AlignVCenter) self.label_2.setObjectName("label_2") self.formLayout_2.setWidget(16, QtWidgets.QFormLayout.FieldRole, self.label_2) spacerItem6 = QtWidgets.QSpacerItem(20, 25, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed) self.formLayout_2.setItem(17, QtWidgets.QFormLayout.FieldRole, spacerItem6) self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setMinimumSize(QtCore.QSize(0, 0)) self.pushButton.setMaximumSize(QtCore.QSize(16777215, 16777215)) font = QtGui.QFont() font.setPointSize(10) font.setBold(True) font.setWeight(75) self.pushButton.setFont(font) self.pushButton.setLayoutDirection(QtCore.Qt.LeftToRight) self.pushButton.setStyleSheet("background-color: rgb(225, 225, 225);\n" "border-style: outset;\n" "border-width: 2px;\n" "border-color: black;\n" "padding: 4px;") self.pushButton.setObjectName("pushButton") self.formLayout_2.setWidget(18, QtWidgets.QFormLayout.FieldRole, self.pushButton) self.label_3 = QtWidgets.QLabel(self.centralwidget) font = QtGui.QFont() font.setItalic(True) self.label_3.setFont(font) self.label_3.setObjectName("label_3") self.formLayout_2.setWidget(13, QtWidgets.QFormLayout.FieldRole, self.label_3) self.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar() self.statusbar.setObjectName("statusbar") self.setStatusBar(self.statusbar) self.retranslateUi() QtCore.QMetaObject.connectSlotsByName(self) def retranslateUi(self): _translate = QtCore.QCoreApplication.translate self.setWindowTitle(_translate("AddItemMenu", "MainWindow")) self.AddItemTitle.setText(_translate("AddItemMenu", "Add Item Info")) self.NameLabel.setText(_translate("AddItemMenu", "Name")) self.QuantityLabel.setText(_translate("AddItemMenu", "Quantity")) self.PriceLabel.setText(_translate("AddItemMenu", "Price (per unit)")) self.DescriptionLabel.setText(_translate("AddItemMenu", "Description")) self.CategoryLabel.setText(_translate("AddItemMenu", "Category")) self.LocationLabel.setText(_translate("AddItemMenu", "Location")) self.BarcodeLabel.setText(_translate("AddItemMenu", "Barcode #")) self.label.setText(_translate("AddItemMenu", "Length (ft)")) self.label_2.setText(_translate("AddItemMenu", "*If the item is wire, please provide it\'s length in feet. If not, leave this field as is.")) self.pushButton.setText(_translate("AddItemMenu", "Submit")) self.label_3.setText(_translate("AddItemMenu", "*Please generate a custom barcode for this item and enter that barcode number in this field ")) #---------------------------------------------------------------------------------------------------- # Values for Categories #---------------------------------------------------------------------------------------------------- self.CategoryInput.addItems(['N/A','Ballast','Boxes','Breakers','Bulbs','Panels/Disconnects', 'Pipes','Small Parts', 'Wire', 'Other']) #---------------------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------------------- # Button Actions #---------------------------------------------------------------------------------------------------- #------------------------------------------ #Submit Button #------------------------------------------ #When the Submit button is clicked -> submitClicked Function SubmitButton = self.pushButton SubmitButton.clicked.connect(self.SubmitClicked) #------------------------------------------ #---------------------------------- #Submit Function def SubmitClicked(self): #Store the user's inputs ItemName = self.NameInput.text() Quantity = self.QuantityInput.text() Price = self.PriceInput.text() Description = self.DescriptionInput.toPlainText() Category = self.CategoryInput.currentText() Location = self.LocationInput.text() Barcode = self.BarcodeInput.text() Length = self.spinBox.value() sellPrice = Price * 1.10 mylist = [ItemName, Quantity, Price, sellPrice, Description, Category, Location, Length, Barcode] #Print in terminal for testing: print("The Submit Button was clicked") print(ItemName, Quantity, Price, Description, Category, Location, Barcode, Length) #Connect to the inventory database (inventory.db) connection = sqlite3.connect("inventory.db") cursor = connection.cursor() cursor = connection.cursor() cursor.execute(''' insert into items (name, quantity, price, sell_price, description, category, location, Length_Ft, Barcode) values (?,?,?,?,?,?,?,?,?) ''', mylist) connection.commit() #Close the connection connection.close() #Switch from this screen to the AdminMenu #(Import AdminMenu here to prevent circular import error) from AdminMenu import Ui_MainDisplay self.win = Ui_MainDisplay() #Define LoginScreen self.win.show() #Show Login Screen self.close() #Close this screen (AdminMenu) #---------------------------------- #---------------------------------------------------------------------------------------------------- if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) ui = Ui_AddItemMenu() ui.show() sys.exit(app.exec_())