I am trying to create a very basic UI. However, I am getting an error saying productName_input not defined" and same with all my other inputs. I am thinking maybe the tables I created are not correct and that is why it is saying input values are not defined but I have no idea what I did wrong.
#Create Tables
cursor.execute("CREATE TABLE hhuschka_products(productID INT AUTO_INCREMENT PRIMARY KEY, productName VARCHAR(45). productPrice DECIMAL(8,2))")
cursor.execute("CREATE TABLE hhuschka_sales (PK INT AUTO_INCREMENT PRIMARY KEY, productID INT, unitSales INT, salesDate DATE)")
#----------------------------------------------------------------------------
#Create UI
customtkinter.set_default_color_theme("blue") #Color for the Window Theme
customtkinter.set_appearance_mode("System")
window = customtkinter.CTk() # Creating the basic window
window.geometry("700x300")
window.title("My first UI")
#window.iconbitmap("uccs.ico")
#window.wm_iconbitmap("uccs.ico")
tk = customtkinter
#Create Input Fields
def clear_inputs():
productName_input.delete(0, tk.END)
productPrice_input.delete(0, tk.END)
unitsSold_input.delete(0, tk.END)
salesDate_input.delete(0, tk.END)
2
Answers
It occurs because you are referencing input widgets (e.g. ‘productName_input’) before they have been created. In order to create input fields, you need to use Tkinter’s ‘Entry’ widget or a custom widget that inherits from it, such as the ones provided by ‘customtkinter’
The error message "productName_input not defined" indicates that the variable ‘productName_input’ has not been defined in the current scope.
Based on the provided code, it seems that the input fields for productName, productPrice, unitsSold, and salesDate are not created before the function clear_inputs() is called.
To fix this issue, you need to create the input fields before defining the function that uses them. You can create the input fields using the tk.Entry() method and assign them to variables like this:
Then, you can call the clear_inputs() function without getting the "not defined" error.
Note that you will also need to position the input fields using a layout manager such as grid() or pack() before running the program.