效果展示
主界面
注册界面
代码展示(包含注释)
import pickle
import tkinter
import tkinter.messagebox
import os
import sys
import Interface
import win32com.client
from tkinter.constants import *
from tkinter import filedialog
import tkinter.messagebox
import pyglet
import os
from memory_pic import *
import base64
def usr_sign_up():
def sign_to_Python():
np = new_pwd.get()
npf = new_pwd_confirm.get()
nn = new_name.get()
try:
with open("usrs_info.pickle", "rb") as usr_file:
exist_usr_info = pickle.load(usr_file)
except FileNotFoundError:
with open("usrs_info.pickle", "wb") as usr_file:
usrs_info = {"admin": "admin"}
pickle.dump(usrs_info, usr_file)
exist_usr_info = usrs_info
if np != npf:
tkinter.messagebox.showerror("Error", "Password and confirm password must be the same!")
elif nn in exist_usr_info:
tkinter.messagebox.showerror("Error", "The user has already signed up! ")
else:
exist_usr_info[nn] = np
with open("usrs_info.pickle", "wb") as usr_file:
pickle.dump(exist_usr_info, usr_file)
tkinter.messagebox.showinfo("Welcome", "You have successfully signed up!")
window_sign_up.destroy()
window_sign_up = tkinter.Toplevel()
window_sign_up.geometry("350x200")
window_sign_up.title("sign up window")
new_name = tkinter.StringVar()
new_name.set("[email protected]")
tkinter.Label(window_sign_up, text="User name:").place(x=10, y=10)
entry_new_name = tkinter.Entry(window_sign_up, textvariable=new_name)
entry_new_name.place(x=150, y=10)
new_pwd = tkinter.StringVar()
tkinter.Label(window_sign_up, text="Password:").place(x=10, y=50)
entry_usr_pwd = tkinter.Entry(window_sign_up, textvariable=new_pwd, show='*')
entry_usr_pwd.place(x=150, y=50)
new_pwd_confirm = tkinter.StringVar()
tkinter.Label(window_sign_up, text="Confirm password:").place(x=10, y=90)
entry_usr_pwd_confirm = tkinter.Entry(window_sign_up, textvariable=new_pwd_confirm, show='*')
entry_usr_pwd_confirm.place(x=150, y=90)
btn_confirm_sign_up = tkinter.Button(window_sign_up, text="Sign up", command=sign_to_Python)
btn_confirm_sign_up.place(x=150, y=130)
class basedesk():
def __init__(self,master):
self.window = master
self.window.title("LOGIN WINDOW")
self.window.geometry("450x300")
self.window.iconphoto(False, tkinter.PhotoImage(file='meCROP.png'))
initface(self.window)
class initface():
def __init__(self,master):
self.tk = master
self.initface = tkinter.Frame(self.tk, height=400, width=500)
self.initface.pack()
self.canvas = tkinter.Canvas(self.initface, height=300, width=400)
self.get_pic(welcome_gif, 'welcome.gif')
self.image_file = tkinter.PhotoImage(file='welcome.gif')
self.canvas.create_image(0, 0, anchor='nw', image=self.image_file)
self.canvas.pack(side='top')
os.remove('welcome.gif')
Label1 = tkinter.Label(self.initface, text='User name:')
Label1.place(x=50, y=150)
self.Label2 = tkinter.Label(self.initface, text='Password name:')
self.Label2.place(x=50, y=190)
self.var_usr_name = tkinter.StringVar()
self.var_usr_name.set('[email protected]')
self.var_usr_pwd = tkinter.StringVar()
self.entry_usr_name = tkinter.Entry(self.initface, textvariable=self.var_usr_name)
self.entry_usr_name.place(x=160, y=150)
self.entry_usr_pwd = tkinter.Entry(self.initface, show='*', textvariable=self.var_usr_pwd)
self.entry_usr_pwd.place(x=160, y=190)
btn_login = tkinter.Button(self.initface, text="Login", command=self.usr_login)
btn_login.place(x=170, y=230)
btn_sign_up = tkinter.Button(self.initface, text="Sign up", command=usr_sign_up)
btn_sign_up.place(x=270, y=230)
btn = tkinter.Button(self.initface, text='EXIT', command=self.change)
btn.pack()
def get_pic(self, pic_code, pic_name):
image = open(pic_name, 'wb')
image.write(base64.b64decode(pic_code))
image.close()
def usr_login(self):
usr_name = self.var_usr_name.get()
usr_pwd = self.var_usr_pwd.get()
try:
with open("usrs_info.pickle", "rb") as usr_file:
usrs_info = pickle.load(usr_file)
except FileNotFoundError:
with open("usrs_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]:
tkinter.messagebox.showinfo(title="Welcome", message="How are you! " + usr_name)
self.initface.destroy()
Interfaced(self.tk)
else:
tkinter.messagebox.showerror(message="Error,your password is wrong,try again")
else:
is_sign_up = tkinter.messagebox.askyesno("Welcome", "You have not sign up yet.Sign up today?")
if is_sign_up:
usr_sign_up()
def change(self,):
sys.exit(1)
class Interfaced():
def __init__(self, master):
self.master = master
self.face1 = tkinter.Frame(self.master,)
self.face1.pack()
ttx = Interface.ttsx(self.face1, self.master)
ttx.tkMain("My Digital Image Processing")
def back(self):
self.face1.destroy()
initface(self.master)
if __name__ == '__main__':
root = tkinter.Tk()
basedesk(root)
root.mainloop()