How to Retrieve Data from an MySQL Database and Display it in a GUI?

108 views Asked by At

all. I'm still pretty new to coding, not having written a single piece of code in my life until 4 weeks ago, and I have 2 questions.

First, I've been struggling trying to figure out how to pull specific pieces of data out of a database that contains 3 tables. Secondly, I've been trying to figure out how to display that data in a GUI. All the tutorials I've read and videos I've watched have shown how to enter and delete values from a table using a GUI, but I haven't found anything about retrieving and displaying those values in a GUI. The closest I have gotten is retrieving and displaying the needed information in the terminal.

I'm using Python 3.12.0 along with CustomTkinter to make a GUI for my MySQL 8.3 database. My database is "HardwareDB" containing tables "doitbest", "truevalue", and "reference". The tables contain columns with headings, such as SKU, Description, Price, Model Number, PrimaryUPC, etc. The basic idea is that I would scan a UPC barcode or enter a Model or SKU number into an entry box on the GUI and then have all the relevant information from both Do-It Best and True Value pop up in said GUI. This way I can compare the two side-by-side when doing our weekly orders. The "reference" table should allow me to compare similar, though not necessarily the same, products between the "doitbest" and "truevalue" tables.

When it comes to retrieving specific pieces of data this is closest I've come:

search = "SELECT Description FROM doitbest, truevalue, reference WHERE PrimaryUPC = UPC_entry.get()"
mycursor.execute(search)
myresult = mycursor.fetchall()
for x in myresult:
        print(x)

The idea behind this was that I scan a barcode into the entry box represented by UPC_entry = customtkinter.CTkEntry but this doesn't work. It says, "mysql.connector.errors.ProgrammingError: 1630 (42000): FUNCTION upc_entry.get does not exist." However, if I replace the UPC_entry.get() with a barcode, it comes back with the relevant data in the terminal.

The second problem is how to display this data in the GUI rather than just in the terminal. Like I stated above, I haven't been able to really find any information about that. For aesthetic reasons, I wanted to use entry boxes/widgets, but instead of using them to enter information, I wanted to retrieve the data and display them in the boxes. My other thought would be to use a combination of frames, background color, and CTklabel to mimic the look of the entry boxes/widgets. I'm not dead set on that, however. I would settle for anything that would make it easy to compare the information. I just didn't know if you guys would have any suggestions for that. Heck. I'm not even deadset on CustomTkinter if you guys have a better suggestion.

0

There are 0 answers