Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize account login by interaction between python tkinter and Mysql database

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the relevant knowledge of "how to achieve account login between python tkinter and Mysql database". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The database password has been implemented in this example, and the table structure of the database is as follows:

Information that has been inserted in the table:

The realization idea is that after the user completes the account password input and clicks the login button, the program first connects to the database, and then according to the parameters provided by the user

Issue the corresponding query statement and give the corresponding response according to the returned query results.

Code implementation

#-*-coding: utf-8-*-"Created on Tue Nov 6 14:29:54 2018Description: password authentication for tkinter 1. Verify with the database Version: @ author: HJY "" import tkinter as tkfrom tkinter import messageboximport sysimport pymysql class loginf (): def _ _ init__ (self,master): self.master = master self.face = tk.Frame (self.master,) self.face.pack () tk.Label (self.face,text=' account'). Pack () self.t_account = tk.Entry (self.face) ) self.t_account.pack () tk.Label (self.face,text=' password') .pack () self.t_password = tk.Entry (self.face,) self.t_password.pack () btn_login = tk.Button (self.face,text='login',command=self.login) btn_login.pack () def login (self ): account = self.t_account.get () password = self.t_password.get () # null operation: slightly print (account,password) # Database processing connection = pymysql.connect (host='localhost',user='root' Port=3306) try: with connection.cursor () as cursor: command1 = "use password "command2 =" select password from passbook where account = (% s) "cursor.execute (command1) result = cursor.execute (command2) (account) connection.close () except: sys.exit () else: if result = = 0: print ('no this clients') Tk.messagebox.showerror ('Info', "Account Not Exist!") Else: print ('find results:', result) if cursor.fetchone () [0] = = password: print ('Login results fulfilled') Tk.messagebox.showinfo ('Info', "Login successfully!") # destroy the login interface and generate the login interface self.face.destroy () homef (self.master) else: print ('password input error') tk.messagebox.showerror (' Info', "Password Error!") Class homef (): def _ init__ (self,master): self.master = master self.face = tk.Frame (self.master,) self.face.pack () btn_showinfo = tk.Button (self.face,text='info',command=self.showinfo) btn_showinfo.pack () def showinfo (self ): pass if _ _ name__ ='_ _ main__': root = tk.Tk () root.title ('Login with password') root.geometry (' 200x200') loginf (root) root.mainloop ()

Example of effect:

This is the end of the content of "how to achieve account login between python tkinter and Mysql database". Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report