Dec-16-2022, 02:33 AM
Hello,
I have this chunk of code from my PyQt GUI that gets a result from a SQLite table and uses that result to do a math calculation.
Snippet:
Output:
Thanks in advance.
Full function (If it helps):
I have this chunk of code from my PyQt GUI that gets a result from a SQLite table and uses that result to do a math calculation.
Snippet:
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 |
else : #Connect to the inventory database (inventory.db) connection = sqlite3.connect(InventoryDatabase) cursor = connection.cursor() cursor.execute( "SELECT Sell_Price_$ FROM items WHERE Name = ?" ,(SelectedItemName,)) connection.commit() SellPrice = cursor.fetchone() # #Update the quantity # cursor.execute("UPDATE items SET Quantity = Quantity - ? WHERE Name = ?",(SelectedItemQuantity, SelectedItemName,)) # connection.commit() #Close the connection connection.close() print ( 'Selcted Item Quantity: ' , SelectedItemQuantity) x = float (SelectedItemQuantity) print ( 'Float Value = ' , x) y = SellPrice[ 0 ] print ( "y = " ,y) z = float (y) print ( 'x*z= ' , x * z) MaterialUsedPrice2 = x * z #Calculate the Price of Material Used #MaterialUsedPrice = SelectedItemQuantity * SellPrice print ( 'The Total Price for the' , '(' ,x, ')' , SelectedItemName, ' Used is: $' , MaterialUsedPrice2) |
Output:2 , 1/2" PVC Coupling
('PVC',)
Selcted Item Quantity: 2
Float Value = 2.0
y = 1.5
x*z= 3.0
The Total Price for the ( 2.0 ) 1/2" PVC Coupling Used is: $ 3.0
#I don't know why this gets printed (again...Since it's already been printed above (Selcted Item Quantity: 2
Float Value = 2.0) and I don't know why the values are 0)
0 , -
None
Selcted Item Quantity: 0
Float Value = 0.0
y = SellPrice[0]
TypeError: 'NoneType' object is not subscriptable
I get this error and I don't know why (When I do print("y = ",y) I get 1.5, which is the correct value, so why am I getting this error?)Error:y = SellPrice[0]
TypeError: 'NoneType' object is not subscriptable
Why do I get this error and how do I fix it?Thanks in advance.
Full function (If it helps):
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 |
def SubmitClicked( self ): #Get User Inputted Quantity & Material #Probably going to have to do it the long way: Do all 22 comboBoxes individually. for widget in self .MaterialUsedFrame.children(): if isinstance (widget, QSpinBox): SelectedItemQuantity = widget.text() if isinstance (widget,QComboBox): SelectedItemName = widget.currentText() print (SelectedItemQuantity, ',' ,SelectedItemName) #Connect to the inventory database (inventory.db) connection = sqlite3.connect(InventoryDatabase) cursor = connection.cursor() cursor.execute( "SELECT Main_Category FROM items WHERE Name = ?" ,(SelectedItemName,)) connection.commit() Result = cursor.fetchone() #Close the connection connection.close() print (Result) if Result = = ( 'Wire' ,): #Connect to the inventory database (inventory.db) connection = sqlite3.connect(InventoryDatabase) cursor = connection.cursor() cursor.execute( "SELECT Price_Per_Ft FROM items WHERE Name = ?" ,(SelectedItemName,)) connection.commit() PricePerFt = cursor.fetchone() #Close the connection connection.close() print (PricePerFt) #Might be better off making all those SpinBoxes Labels #& Just setting the text to the price for widget in self .MaterialPriceFrame.children(): if isinstance (widget, QDoubleSpinBox): widget.setValue( 80.80 ) else : #Connect to the inventory database (inventory.db) connection = sqlite3.connect(InventoryDatabase) cursor = connection.cursor() cursor.execute( "SELECT Sell_Price_$ FROM items WHERE Name = ?" ,(SelectedItemName,)) connection.commit() SellPrice = cursor.fetchone() # #Update the quantity # cursor.execute("UPDATE items SET Quantity = Quantity - ? WHERE Name = ?",(SelectedItemQuantity, SelectedItemName,)) # connection.commit() #Close the connection connection.close() print ( 'Selcted Item Quantity: ' , SelectedItemQuantity) x = float (SelectedItemQuantity) print ( 'Float Value = ' , x) y = SellPrice[ 0 ] print ( "y = " ,y) z = float (y) print ( 'x*z= ' , x * z) MaterialUsedPrice2 = x * z #Calculate the Price of Material Used #MaterialUsedPrice = SelectedItemQuantity * SellPrice print ( 'The Total Price for the' , '(' ,x, ')' , SelectedItemName, ' Used is: $' , MaterialUsedPrice2) #---------------------------------------------------------------------------------------------------- |