python设计一个登录界面
创始人
2024-12-27 16:03:59
0

游戏登录界面

  • 1.设计登录界面
    • 1.1导入需要的工具包
    • 1.2窗口显示
    • 1.3登录界面图片显示
    • 1.4 用户名设置默认值
    • 1.5标签按钮输入框显示
  • 2.登录功能实现
    • 2.1用户数据存储
    • 2.2登录和注册
      • 2.2.1登录功能实现
      • 注册功能实现

1.设计登录界面

1.1导入需要的工具包

import tkinter as tk from PIL import Image, ImageTk import pickle from tkinter import messagebox import subprocess 

1.2窗口显示

window = tk.Tk() window.title("Welcome") window.geometry('500x600') 

1.3登录界面图片显示

image = Image.open("welcome.gif") photo = ImageTk.PhotoImage(image) 

1.4 用户名设置默认值

value = "GaoYue" entry_var = tk.StringVar(window) entry_var.set(value) 

1.5标签按钮输入框显示

label1_image = tk.Label(window,image=photo) label1_image.place(x=10,y=10) label2 = tk.Label(window,text='User name',width=10,height=5) label2.place(x=40,y=130) label3 = tk.Label(window,text='password',width=10,height=5) label3.place(x=40,y=180) label4 = tk.Entry(window,width=30,bd=5) label4.place(x=140,y=210) label5 = tk.Entry(window,textvariable=entry_var,width=30,bd=5) label5.place(x=140,y=160)  button1 = tk.Button(window,text='Loign',width=10,command=usr_login) button1.place(x=140,y=280) button2 = tk.Button(window,text='Sign up',width=10,command=usr_sign_up) button2.place(x=250,y=280) 

在这里插入图片描述

2.登录功能实现

2.1用户数据存储

def usr_login():     usr_name = label5.get()     usr_pwd=label4.get()     print(usr_name)     try:         with open("usrs_info.pickle",'rb') as usr_file:             print("1")             usrs_info = pickle.load(usr_file)             print(usrs_info)     except FileNotFoundError:         with open("usrs_info.pickle",'wb') as usr_file:             print("2")             usrs_info = {'admin':'admin'}             pickle.dump(usrs_info,usr_file) 

2.2登录和注册

2.2.1登录功能实现

print("ok") print("usr_name:",usr_name) if usr_name in usrs_info:     print("3")     if usr_pwd  == usrs_info[usr_name]:         tk.messagebox.showinfo(title="Welcome",message="How are you"+usr_name)         tk.messagebox.showinfo(title="Game Start", message="Let's start the game!")         subprocess.run(["python", "井字棋.py"])     else:         tk.messagebox.showerror(message="Error,your password is wrong,try again.") else:     print("4")     is_sign_up = tk.messagebox.askyesno(title="Welcome",message="You have not sign up yet.sign up today?") 

注册功能实现

def sign_up():     nn = entry9.get()     np = entry10.get()     npf = entry11.get()     with open('usrs_info.pickle','rb') as usr_file:         exist_usr_info = pickle.load(usr_file)     if np != npf:         tk.messagebox.showerror("Error","The user has already signed up!")     elif nn in exist_usr_info:         print("已经注册过了")         tk.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)         tk.messagebox.showinfo("Welcome","You have successfully signed up!")         window.destroy() button3 = tk.Button(window, text='Sign up', width=10,command=sign_up) button3.place(x=140, y=150) print("开始注册") 

在这里插入图片描述

相关内容

热门资讯

此事引发网友热议!微乐小程序脚... 此事引发网友热议!微乐小程序脚本(辅助)一贯确实有辅助工具(有挂方略)1.微乐小程序脚本 选牌创建新...
6分钟辅助!蜀山四川小程序脚本... 6分钟辅助!蜀山四川小程序脚本,其实是真的有辅助方法(有挂攻略)蜀山四川小程序脚本是不是有人用挂微扑...
第1分钟辅助!约局吧透视挂下载... 第1分钟辅助!约局吧透视挂下载,aapoker公共底牌,方针教程(有挂方略)1、完成约局吧透视挂下载...
第7分钟辅助!牵手跑得软件,果... 第7分钟辅助!牵手跑得软件,果然有辅助脚本(揭秘有挂)1、牵手跑得软件免费辅助多个强度级别选择2、牵...
目前来看!老友辅助工具(辅助)... 目前来看!老友辅助工具(辅助)真是是有辅助软件(有挂头条)小薇(辅助器软件下载)致您一封信;亲爱老友...
五分钟辅助!wepoker数据... 五分钟辅助!wepoker数据分析工具,hhpoker软件靠谱吗,练习教程(揭秘有挂)1、超多福利:...
第八分钟辅助!微信西楚辅助,都... 第八分钟辅助!微信西楚辅助,都是有辅助教程(有挂助手)1、首先打开微信西楚辅助辅助器下载最新版本,在...
据通报!广东雀神智能插件辅助脚... 据通报!广东雀神智能插件辅助脚本(辅助)一贯真的有辅助技巧(确实有挂)1、下载好广东雀神智能插件辅助...
五分钟辅助!wepoker私人... 五分钟辅助!wepoker私人定制透视,wepoker永久免费脚本,烘培教程(真是有挂)wepoke...
第一分钟辅助!如何使用掌酷十三... 第一分钟辅助!如何使用掌酷十三张脚本,一直是有辅助插件(有挂分析)1、不需要AI权限,帮助你快速的进...