Home > OS >  How do I query a Data from a MySQL database using Tkinter Entry
How do I query a Data from a MySQL database using Tkinter Entry

Time:10-16

I have a MySQL Database called "Employees" which has 5 Columns and has 20 data's inside. I want to query a single data and update it on tkinters interface for example:

conn = mysql.connect(host='localhost', database='employees', port='3306', user='root', password='admin@123')

cursor = conn.cursor()

queryentry = Entry(main, width=20)
namelabel = Label(main, text = '')
namelabel.place(x=, y=)

def search():
   sear = queryentry.get()
   asd = cursor.execute(''SELECT name FROM all_employees WHERE idnum=queryentry'')

modifname = namelabel.config(text=asd)

Is there another method of getting the input of the user and return it to the WHERE clause?

CodePudding user response:

I think you're on the right track but shouldn't idnum be set to sear?

You would then need a button to call the function:

query_button = Button(main,text="Query",command=search)
query_button.grid(column=1,row=1)

Not sure what you want to do with this query but you would either have to add a return or print statement to your function. I don't know how you would assign a variable to the output of the function so you could make asd a global variable and then return it.

def search():
   sear = queryentry.get()
   global asd
   asd = cursor.execute(''SELECT name FROM all_employees WHERE idnum=sear'')
   return asd

  • Related