简体   繁体   中英

I want to make gui with python to display table in RDS MySQL DB

I want to make gui with python to display table in RDS MySQL DB but I have that error

 File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1550, in __call__
return self.func(*args)
 File "GUI.py", line 30, in query
 records = c.fetchall()
 File "/usr/local/lib/python2.7/dist-packages/mysql/connector/cursor_cext.py", line 488, in fetchall
  raise errors.InterfaceError("No result set to fetch from.")
  InterfaceError: No result set to fetch from.

the code

try:
    # for Python2
    from Tkinter import *
except ImportError:
    # for Python3
    from tkinter import *
from PIL import ImageTk,Image
import sqlite3
import mysql.connector


root = Tk()
root.title('welcome reham')
#root.iconbitmap('@/home/A/x/GUI.xbm')
root.geometry("400x400")

#create query botton to show records in DB
def query():
    connection = mysql.connector.connect(host="*****",
                                 user="admin",
                                 passwd="******",
                                 database="attendance1")
    c = connection.cursor()
    c.execute = ("SELECT *, oid FROM empolyee")
    records = c.fetchall()
    print(records)

    print_records = ''
    for record in records:
    print_records += str(records) + "/n"
    query_labal = labal(root, text=print_records)
    query_labal.grid(row=2, column=0, columnspan=2, pady=10, padx=10, ipadx=137)
connection.commit()
connection.close()

#create query buttom
query_btn = Button(root, text="show records", command=query)
query_btn.grid(row=1, column=0, columnspan=2, pady=10, padx=10, ipadx=137)

root.mainloop() 

To execute query it has to be

c.execute("SELECT *, oid FROM empolyee") 

without =


Using = you created variable c.execute instead of executing query so later fetchall() couldn't get results - because query was not executed - and it shows No result set to fetch from.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM