日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python tkinter数据库通讯录_TKINTER--GUI连接数据库登陆

發(fā)布時間:2025/3/12 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python tkinter数据库通讯录_TKINTER--GUI连接数据库登陆 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

#-*- coding:UTF-8 -*-

import tkinter.messagebox

import tkinter as tk

import pymysql

# 構(gòu)造窗口

window = tk.Tk()

window.title('登陸窗口')

window.geometry('450x300')

# 構(gòu)造畫布

canvas = tk.Canvas(window,height=200,width=500)

image_file = tk.PhotoImage(file='welcome.gif')

image=canvas.create_image(0,0,anchor='nw',image=image_file)

canvas.pack(side='top')

tk.Label(window,text='Username:').place(x=50,y=150)

tk.Label(window,text='Password:').place(x=50,y=190)

var_user_name = tk.StringVar()

var_user_name.set('example@python.com')

entry_user_name = tk.Entry(window,textvariable=var_user_name)

entry_user_name.place(x=160,y=150)

var_user_password=tk.StringVar()

entry_user_password = tk.Entry(window,textvariable=var_user_password,show='*')

entry_user_password.place(x=160,y=190)

def user_login():

# 獲取label中的輸入

user_name = var_user_name.get()

user_password = var_user_password.get()

db = pymysql.connect(host="localhost", user="root",

password="123456", db="test", port=3306)

try:

cursor = db.cursor()

sql='select * from users_name where username = "'"%s"'";'%user_name #動態(tài)sql拼接

cursor.execute(sql)

result = cursor.fetchall()

if user_name == result[0][1] and user_password == result[0][2]:

tk.messagebox.showinfo(title='welcome',message='How are you? ' + str(user_name))

else:

tk.messagebox.showerror(message='Erro,your password is wrong,try again!')

except Exception as e:

tk.messagebox.showerror(e)

finally:

db.close()

def user_registe():

pass

# 構(gòu)造登陸/注冊按鈕

btn_login = tk.Button(window,text='Login',command=user_login)

btn_login.place(x=170,y=230)

btn_sign_up = tk.Button(window,text='Regist',command=user_registe)

btn_sign_up.place(x=270,y=230)

window.mainloop()

注冊的還沒寫完,今天就先到這里!

總結(jié)

以上是生活随笔為你收集整理的python tkinter数据库通讯录_TKINTER--GUI连接数据库登陆的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。