从MySQL获取数据库以输出标签Tkinter Python

从MySQL获取数据库以输出标签Tkinter Python,python,mysql,sql,tkinter,tkinter-entry,Python,Mysql,Sql,Tkinter,Tkinter Entry,我希望将MySQL数据库的SQL查询结果放在Tkinter的一个特定标签中,这个标签是我创建的,名为quanker_resu2。但当我运行代码时,我所拥有的只是输入的内容。 我认为问题出在函数def recherche或def BREANT_resu2中。 我是一个初学者,请友善一点 谢谢大家! 多亏了你们,我才发现问题所在。我不知道如何使用函数 def fiche_acteur(): with connection.cursor() as cursor: xxx=s2.get()

我希望将MySQL数据库的SQL查询结果放在Tkinter的一个特定标签中,这个标签是我创建的,名为quanker_resu2。但当我运行代码时,我所拥有的只是输入的内容。

我认为问题出在函数def recherche或def BREANT_resu2中。 我是一个初学者,请友善一点
谢谢大家!

多亏了你们,我才发现问题所在。我不知道如何使用函数

def fiche_acteur():
with connection.cursor() as cursor:
    xxx=s2.get()
    sql = "SET @name='%" + xxx + "%';";
    cursor.execute(sql)
    cursor.execute("""SELECT primaryName, birthYear, deathYear FROM name_basics 
                       WHERE primaryName like @name;""")
    result = cursor.fetchone()
    deathYear = result[2]
    if deathYear is None or deathYear =='':
        deathYear = '~~'
    cursor.execute("""SELECT primaryTitle,averageRating FROM title_principals
                       JOIN title_basics ON title_principals.tconst = title_basics.tconst
                       JOIN name_basics ON title_principals.nconst = name_basics.nconst
                       JOIN title_ratings on title_principals.tconst = title_ratings.tconst
                       WHERE primaryName like @name AND numVotes>1000
                       ORDER BY averageRating DESC
                       LIMIT 3;""")
    films = cursor.fetchall()
    liste_complete=[result,films]
    df_lc=pd.DataFrame(liste_complete)
    df_lc1=df_lc.rename(columns={0:'',1:'',2:''})
resultLabel2.config(text=df_lc1.to_string(index=False))


#Fenêtre principale
root = tk.Tk() 
root.geometry("1800x900") 
root.title("MoviePro")

root.configure(background='black')

#Style custom des onglets
style=tki.Style()
style.configure("fond.TFrame",background="black", foreground="white", borderwidth=1, font=("Ubuntu", 16, 'bold'))
style.configure("TNotebook", background="black", foreground="white",borderwidth=2, padding=[100,20] ,tabmargins= [2, 5, 2, 0], font=("Ubuntu", 18, 'bold'))
style.configure("TNotebook.Tab", background="black", foreground="white",borderwidth=2, padding= [100, 20], font=("Ubuntu", 18, 'bold'))

#Image logo
load= Image.open("CineLogo1.png")
resized= load.resize((400,250),Image.ANTIALIAS)
render = ImageTk.PhotoImage(resized)
img = tk.Label(root, image=render, height=20,width=80)
img.image = render
img.place(relx=0.14,rely=0.04,relwidth=0.21,relheight=0.2)

#------------- Système d'onglets
onglets = tki.Notebook(root,width='100', height="20", style='TNotebook')   
onglets.place(relx=0,rely=0.25,relwidth=1.05,relheight=0.7)

#-------------- Onglet Acteur
o2 = tki.Frame(onglets,style='fond.TFrame')     
onglets.add(o2, text='Acteur(trice)')    
message2 = tk.Label(o2, bg="black",foreground="white", borderwidth=0 , text="Vous recherchez des informations sur un(e) acteur(rice)? Nous pouvons vous aider!!! ",font=("Ubuntu", 18))
message2.place(relx=0.1,rely=0,relwidth=0.8,relheight=0.1)
resultLabel2 = tk.Label(o2, text="", bg="black",fg="white",activebackground="goldenrod",font=("Ubuntu", 18))
resultLabel2.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.4)
button=tk.Button(o2,text="Rechercher", command=fiche_acteur, bg="black",fg="white",activebackground="goldenrod",font=("Ubuntu", 18))
s2= tk.StringVar()
search= tk.Entry(o2, width=110, textvariable=s2,font=("Ubuntu", 22)).place(relx=0.1,rely=0.1,relwidth=0.8,relheight=0.1)
button.place(relx=0.1,rely=0.21,relwidth=0.8,relheight=0.08)

# Instruction pour ouvrir la fenêtre et gestion des modifications 
root.mainloop() 
这段代码运行得很好:!非常感谢。
当然,您必须导入每个库tkinter、config、pandas。。并将代码连接到服务器和数据库。

您正在使用参数,但是否正在传递值?谢谢您的评论。我真的不知道怎么做def recherche:。。。。def submitrecherche:user=。。。。密码=。。。loginqueryuser,密码def loginqueryuser,密码:`我也不知道你用的是什么查询,所以我很难说出你想传递什么数据。你所说的@you从未调用过2函数是什么意思。
def fiche_acteur():
with connection.cursor() as cursor:
    xxx=s2.get()
    sql = "SET @name='%" + xxx + "%';";
    cursor.execute(sql)
    cursor.execute("""SELECT primaryName, birthYear, deathYear FROM name_basics 
                       WHERE primaryName like @name;""")
    result = cursor.fetchone()
    deathYear = result[2]
    if deathYear is None or deathYear =='':
        deathYear = '~~'
    cursor.execute("""SELECT primaryTitle,averageRating FROM title_principals
                       JOIN title_basics ON title_principals.tconst = title_basics.tconst
                       JOIN name_basics ON title_principals.nconst = name_basics.nconst
                       JOIN title_ratings on title_principals.tconst = title_ratings.tconst
                       WHERE primaryName like @name AND numVotes>1000
                       ORDER BY averageRating DESC
                       LIMIT 3;""")
    films = cursor.fetchall()
    liste_complete=[result,films]
    df_lc=pd.DataFrame(liste_complete)
    df_lc1=df_lc.rename(columns={0:'',1:'',2:''})
resultLabel2.config(text=df_lc1.to_string(index=False))


#Fenêtre principale
root = tk.Tk() 
root.geometry("1800x900") 
root.title("MoviePro")

root.configure(background='black')

#Style custom des onglets
style=tki.Style()
style.configure("fond.TFrame",background="black", foreground="white", borderwidth=1, font=("Ubuntu", 16, 'bold'))
style.configure("TNotebook", background="black", foreground="white",borderwidth=2, padding=[100,20] ,tabmargins= [2, 5, 2, 0], font=("Ubuntu", 18, 'bold'))
style.configure("TNotebook.Tab", background="black", foreground="white",borderwidth=2, padding= [100, 20], font=("Ubuntu", 18, 'bold'))

#Image logo
load= Image.open("CineLogo1.png")
resized= load.resize((400,250),Image.ANTIALIAS)
render = ImageTk.PhotoImage(resized)
img = tk.Label(root, image=render, height=20,width=80)
img.image = render
img.place(relx=0.14,rely=0.04,relwidth=0.21,relheight=0.2)

#------------- Système d'onglets
onglets = tki.Notebook(root,width='100', height="20", style='TNotebook')   
onglets.place(relx=0,rely=0.25,relwidth=1.05,relheight=0.7)

#-------------- Onglet Acteur
o2 = tki.Frame(onglets,style='fond.TFrame')     
onglets.add(o2, text='Acteur(trice)')    
message2 = tk.Label(o2, bg="black",foreground="white", borderwidth=0 , text="Vous recherchez des informations sur un(e) acteur(rice)? Nous pouvons vous aider!!! ",font=("Ubuntu", 18))
message2.place(relx=0.1,rely=0,relwidth=0.8,relheight=0.1)
resultLabel2 = tk.Label(o2, text="", bg="black",fg="white",activebackground="goldenrod",font=("Ubuntu", 18))
resultLabel2.place(relx=0.1,rely=0.3,relwidth=0.8,relheight=0.4)
button=tk.Button(o2,text="Rechercher", command=fiche_acteur, bg="black",fg="white",activebackground="goldenrod",font=("Ubuntu", 18))
s2= tk.StringVar()
search= tk.Entry(o2, width=110, textvariable=s2,font=("Ubuntu", 22)).place(relx=0.1,rely=0.1,relwidth=0.8,relheight=0.1)
button.place(relx=0.1,rely=0.21,relwidth=0.8,relheight=0.08)

# Instruction pour ouvrir la fenêtre et gestion des modifications 
root.mainloop()