import tkinter as tk
import tkinter.messagebox
import pickle
window = tk.Tk()
window.title("Subscribes Manage PLT For Students from DUT-PJ")
window.geometry("680x200")
# 弹窗提示文字
tk.messagebox.showwarning(title="Something You Must Know Before Use",
message="Welcome to ChengFeng Tech.Studio! This program will be used as subscribe service only!")
# 加载欢迎图片
canvas = tk.Canvas(window)
image_file = tk.PhotoImage(file='E:\logo.gif')
image = canvas.create_image(8, 0, anchor='nw', image=image_file)
canvas.place(x=25, y=25)
# 设置默认值为空
var_acc = tk.StringVar()
var_pwd = tk.StringVar()
import tkinter as tk
# 账号密码输入区
tk.Label(window, text="Input your DUT account: ", font=('Arial', 14)).place(x=200, y=25) # 账号文字
acc = tk.Entry(window, show=None, textvariable=var_acc, font=('Arial', 14)).place(x=420, y=25) # 输入账号形式
tk.Label(window, text="Input your password:", font=('Arial', 14)).place(x=200, y=70) # 密码文字
pwd = tk.Entry(window, show="*", textvariable=var_pwd, font=('Arial', 14)).place(x=420, y=70) # 输入密码形式
def Login_password_test():
accint = var_acc.get() # 获取输入的账号
pwdint = var_pwd.get() # 获取输入的密码
# 尝试查找和匹配账号和密码
try:
with open('users_info.pickle', 'rb') as user_file:
users_info = pickle.load(user_file)
# 若查找出现错误
except FileNotFoundError:
with open('users_info.pickle', 'wb') as user_file:
users_info = {'admin': 'admin'}
pickle.dump(users_info, user_file)
if acc in users_info:
# 账号和密码匹配
if pwd == users_info[acc]:
tk.messagebox.showinfo(title="Complete", message="Login successfully, welcome back!")
# 账号和密码不匹配
else:
tk.messagebox.showerror(title="Failed", message="Invalid login request, check your DUT number or password you input just now.")
# 未知账号提示注册
else:
is_sign_up = tk.messagebox.askyesno(title="Information", message="It seems that you havn't sign up yet. Sign up now?")
if is_sign_up:
Signup()
def Signup():
def sign_to_CF():
newpwd = intnew_userpwd.get()
newpwdconfirm = intnew_userpwd_confirm.get()
newacc = intnew_user.get()
with open("users_info.pickle", "rb") as user_file:
exist_user_info = pickle.load(user_file)
if newpwd != newpwdconfirm:
tk.messagebox.showerror(title="Failed",
message="Invalid sign up request, check your twice iuput. They must be the same!")
elif newacc in exist_user_info:
tk.messagebox.showerror(title="Failed",
message="Invalid sign up request, check the account you input just now. It has already exist!")
else:
exist_user_info[newacc] = newpwd
with open("users_info.pickle", "wb") as user_file:
pickle.dump(exist_user_info, user_file)
tk.messagebox.showinfo(title="Complete", message="Welcome to be a membership of Chengfeng Tech. Studio!")
window_sign_up.destroy()
window_sign_up = tk.Toplevel(window)
window_sign_up.geometry("620x300")
window_sign_up.title("Sign up")
new_user = tk.StringVar()
new_user.set("example")
tk.Label(window_sign_up, text="Input an unused DUT number: ", font=('Arial', 14)).place(x=20, y=20) # 注册账号提示
intnew_user = tk.Entry(window_sign_up, show=None, font=('Arial', 14)).place(x=300, y=20) # 新账号输入框
tk.Label(window_sign_up, text="Input your password: ", font=('Arial', 14)).place(x=20, y=80) # 设置密码提示
intnew_userpwd = tk.Entry(window_sign_up, show="*", font=('Arial', 14)).place(x=300, y=80) # 新密码输入框
new_pwd_confirm = tk.StringVar()
tk.Label(window_sign_up, text="Confirm your password: ", font=('Arial', 14)).place(x=20, y=140) # 确认密码提示
intnew_userpwd_confirm = tk.Entry(window_sign_up, show="*", font=('Arial', 14)).place(x=300, y=140) # 确认密码输入框
# 注册确认按钮
tk.Button(window_sign_up, text='Sign up', font=('Arial', 10), width=10, height=1, command=sign_to_CF).place(x=300, y=200)
# 登录按钮
tk.Button(window, text='Login', font=('Arial', 10), width=10, height=1, command=Login_password_test).place(x=280, y=125)
# 注册按钮
tk.Button(window, text='Sign Up By DUT Numbers', font=('Arial', 10), width=22, height=1, command=Signup).place(x=400,
y=125)
window.mainloop() # 循环
这个代码点注册之后总是弹出AttributeError: 'NoneType' object has no attribute 'get'
哪位高人能给debug下