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:
And these are the variables I have that store the user's input:
If I try to run my code:
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:
1 2 3 4 |
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) |
1 2 3 4 5 6 7 8 9 10 11 |
#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] |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
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_()) |