In the above, I only gave the interface code , The code of the database part is annotated , Originally, I wanted to build a complete login and data visualization interface after the data visualization interface was completed , But because there are other things to do , So I packaged the previous code , In this way, the whole code contains only three functions (create_root,new_root,sql_information), It is clear and reusable , Share the discussion with you :
from tkinter import * import pymysql # Create root window , And add components def create_root(): root =
Tk() root.title(' Sign in ') root.resizable(0, 0) # Set window size immutable canvas = Canvas(root) #
Add canvas canvas.pack(side='top', fill=BOTH) canvas.create_window(100, 50,
window=Label(root, font=(' Song style ', 10), text=' user name ', justify='left', padx=5,
pady=4)) # among 100,50 Is the offset from the canvas , The upper left corner is 0,0 canvas.create_window(100, 90,
window=Label(root, font=(' Song style ', 10), width=5, text=' password ', justify='left',
padx=5, pady=4)) # Account password input box zh_entry = Entry(root, borderwidth=3) password_entry
= Entry(root, borderwidth=3, show='*') canvas.create_window(210, 50,
window=zh_entry) canvas.create_window(210, 90, window=password_entry)
canvas.create_window(330, 90, window=Label(root, text=' Forget the password ', fg='red',
font=(' Song style ', 10))) # Create canvas background photo = PhotoImage(file='bg.png')
canvas.create_image(200, 150, image=photo) # button Click event def callback(): user =
int(zh_entry.get()) password = int(password_entry.get()) user_information =
sql_information('select * from user_information') if user ==
user_information[0][0] and password == user_information[0][1]: #
When extracting data from a database , Will return the data of each row in the form of tuples , That is, each line constitutes a tuple , And all the rows make up a big tuple , That is, nested tuples . student_information
= sql_information('select * from student_information') root.state("iconic") #
Hide window , It's equivalent to minimizing the window new_root(student_information) else: pass
# I didn't write down the event of account password error here , You can write corresponding response events if you need # Create login button canvas.create_window(190, 200,
window=Button(root, width=15, command=callback, bg='#87CEEB', text=' Sign in now '))
mainloop() # Create a new window def new_root(student_information): student_root = Toplevel()
student_root.title(' Student management system ') student_root.resizable(0, 0) head_string = (' Student number ',
' full name ', ' grade ', ' Age ', ' Home address ') for i in range(len(student_information[0])): listbox
= Listbox(student_root, width=20, height=20, bd=4, relief='flat', bg='#E0FFFF')
listbox.pack(side=LEFT, fill=BOTH) listbox.insert(END, head_string[i]) for each
in student_information: listbox.insert(END, each[i]) # Make database connection , afferent sql sentence , Return the required information
def sql_information(sql): connection = pymysql.connect('localhost', 'root',
'*******', "tang_crawler") # I've covered the password here , Just fill in your password when you connect cursor =
connection.cursor() try: cursor.execute(sql) user_information =
cursor.fetchall() except Exception as e: print(e) finally: if connection:
cursor.close() if cursor: connection.close() return user_information if
__name__ == '__main__': create_root()
The login interface is :

 

After clicking login , The data interface is :

The data visualization interface here is not good , One is not finding a good one UI a design chart , And then there is tkinter I don't feel fit to do this . So it's just a simple list of the data .

Technology
©2019-2020 Toolsou All rights reserved,
Huawei 2021 session Hardware Engineer Logical post (FPGA) Super detailed surface !!!Vue-element-admin upgrade ui edition virtual machine VMware Download and install the most detailed tutorial !C++ Move constructor and copy constructor sound of dripping water java Backstage interview pygame Realize full screen mode and adjustable window size mysql Database setting character set configuration modification my.ini file (windows)30 What's the experience of being a junior programmer at the age of 20 C++ Multithreading programming ( Summary of common functions and parameters )python_ cherry tree