python的tkinter做界⾯,直接上源码
# -*- coding: utf-8 -*-
"""
Created on Sun Aug  5 10:34:10 2018
@author: Administrator
"""
import tkinter as tk
ssagebox
import pickle
from UI.MainUi import MainUU
# 窗⼝
window = tk.Tk()
window.title('多⽬标跟踪系统窗⼝')
# 画布放置图⽚
canvas = tk.Canvas(window, height=300, width=500)
imagefile = tk.PhotoImage(file='LD.png')
image = ate_image(0, 0, anchor='nw', image=imagefile)
canvas.pack(side='top')
# 标签⽤户名密码
tk.Label(window, text='⽤户名:').place(x=100, y=150)
tk.Label(window, text='密码:').place(x=100, y=190)
# ⽤户名输⼊框
var_usr_name = tk.StringVar()
entry_usr_name = tk.Entry(window, textvariable=var_usr_name)
entry_usr_name.place(x=160, y=150)
# 密码输⼊框
var_usr_pwd = tk.StringVar()
entry_usr_pwd = tk.Entry(window, textvariable=var_usr_pwd, show='*')
entry_usr_pwd.place(x=160, y=190)
# 登录函数
def usr_log_in():
# 输⼊框获取⽤户名密码
usr_name = var_()
usr_pwd = var_()
# 从本地字典获取⽤户信息,如果没有则新建本地数据库
try:
with open('usr_info.pickle', 'rb') as usr_file:
usrs_info = pickle.load(usr_file)
except FileNotFoundError:
with open('usr_info.pickle', 'wb') as usr_file:
usrs_info = {'admin': 'admin'}
pickle.dump(usrs_info, usr_file)
# 判断⽤户名和密码是否匹配
if usr_name in usrs_info:
if usr_pwd == usrs_info[usr_name]:
message='欢迎您:' + usr_name)
window_sign_up = tk.Toplevel(window)
window_ry('350x200')
window_sign_up.title('登录成功')
bt_confirm_sign_up = tk.Button(window_sign_up, text='打开')
bt_confirm_sign_up.place(x=10, y=10)
bt_confirm_sign_up = tk.Button(window_sign_up, text='重置' )
bt_confirm_sign_up.place(x=10, y=50)
bt_confirm_sign_up = tk.Button(window_sign_up, text='关闭')
bt_confirm_sign_up.place(x=10, y=100)
canvas1=tk.Canvas(window_sign_up, width=200, height=300, bg='white')
canvas1.pack()
#str=usr_name
#MainUU.feature(str)
else:
# ⽤户名密码不能为空
elif usr_name == '' or usr_pwd == '':
# 不在数据库中弹出是否注册的框
else:
is_signup = tk.messagebox.askyesno('欢迎', '您还没有注册,是否现在注册')
if is_signup:
usr_sign_up()
# 注册函数
def usr_sign_up():
# 确认注册时的相应函数
def signtowcg():
# 获取输⼊框内的内容
nn = ()
np = ()
npf = new_()
# 本地加载已有⽤户信息,如果没有则已有⽤户信息为空
try:
with open('usr_info.pickle', 'rb') as usr_file:
exist_usr_info = pickle.load(usr_file)
except FileNotFoundError:
exist_usr_info = {}
# 检查⽤户名存在、密码为空、密码前后不⼀致
import pickle
if nn in exist_usr_info:
elif np == '' or nn == '':
elif np != npf:
# 注册信息没有问题则将⽤户名密码写⼊数据库
else:
exist_usr_info[nn] = np
with open('usr_info.pickle', 'wb') as usr_file:
pickle.dump(exist_usr_info, usr_file)
# 注册成功关闭注册框
window_sign_up.destroy()
# 新建注册界⾯
window_sign_up = tk.Toplevel(window)
window_ry('350x200')
window_sign_up.title('注册')
# ⽤户名变量及标签、输⼊框
new_name = tk.StringVar()
tk.Label(window_sign_up, text='⽤户名:').place(x=10, y=10)
tk.Entry(window_sign_up, textvariable=new_name).place(x=150, y=10)
# 密码变量及标签、输⼊框
new_pwd = tk.StringVar()
tk.Label(window_sign_up, text='请输⼊密码:').place(x=10, y=50)
tk.Entry(window_sign_up, textvariable=new_pwd, show='*').place(x=150, y=50)
# 重复密码变量及标签、输⼊框
new_pwd_confirm = tk.StringVar()
tk.Label(window_sign_up, text='请再次输⼊密码:').place(x=10, y=90)
tk.Entry(window_sign_up, textvariable=new_pwd_confirm, show='*').place(x=150, y=90)
tk.Entry(window_sign_up, textvariable=new_pwd_confirm, show='*').place(x=150, y=90)    # 确认注册按钮及位置
bt_confirm_sign_up = tk.Button(window_sign_up, text='确认注册',
command=signtowcg)
bt_confirm_sign_up.place(x=150, y=130)
# 退出的函数
def usr_sign_quit():
window.destroy()
# 登录注册按钮
bt_login = tk.Button(window, text='登录', command=usr_log_in)
bt_login.place(x=140, y=230)
bt_logup = tk.Button(window, text='注册', command=usr_sign_up)
bt_logup.place(x=210, y=230)
bt_logquit = tk.Button(window, text='退出', command=usr_sign_quit)
bt_logquit.place(x=280, y=230)
# 主循环
window.mainloop()

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。