我能够连接mysql和python
我已经创建了2个标签,我想将值从数据库(MySQL)导入到标签(tkinter),而不是“text1”和“text2”。在
我必须使用的函数是什么?
或
我怎么解决这个问题?在from tkinter import *
from PIL import Image, ImageTk
import pymysql
conn = pymysql.connect(host = "localhost",
user = "root",
passwd = "asdf",
db = "testdb", charset = 'utf8')
curs = conn.cursor(pymysql.cursors.DictCursor)
sql = "select * from test where id=%s and text1=%s and text2=%s"
curs.execute(sql,('A0002','asdfasdfasdf', 'asdfasdfvvwervfvasff'))
class App(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid(row=0)
self.columnconfigure(0,weight=1)
self.rowconfigure(0,weight=1)
self.original = Image.open('Chrysanthemum.jpg')
resized = self.original.resize((400, 300),Image.ANTIALIAS)
self.image = ImageTk.PhotoImage(resized)
self.display = Label(self, image = self.image)
self.display.grid(column=0,row=0)
root = Tk()
root.title("image test")
root.geometry("1000x800+100+100")
root.resizable(0,0)
root.configure(background = 'white')
app = App(root)
rows = curs.fetchall()
label1 = Label(root,text = "text1")
label1.config(wraplength =500)
label1.config(width=80,height=20)
label1.grid(column=1,row=0)
label2 = Label(root,text ="text2")
label2.config(wraplength=910)
label2.config(width=138,height=30)
label2.grid(columnspan=2,row=1)
app.mainloop()