资源简介
用tkinter写的python GUI注册界面实例,包括注册和登录。使用pickle库来序列化用户名和密码
代码片段和文件信息
# View more python learning tutorial on my Youtube and Youku channel!!!
# Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
# Youku video tutorial: http://i.youku.com/pythontutorial
import tkinter as tk
from tkinter import messagebox # import this to fix messagebox error
import pickle
window = tk.Tk()
window.title(‘Welcome to Mofan Python‘)
window.geometry(‘450x300‘)
# welcome image
canvas = tk.Canvas(window height=200 width=500)
image_file = tk.PhotoImage(file=‘welcome.gif‘)
image = canvas.create_image(00 anchor=‘nw‘ image=image_file)
canvas.pack(side=‘top‘)
# user information
tk.Label(window text=‘User name: ‘).place(x=50 y= 150)
tk.Label(window text=‘Password: ‘).place(x=50 y= 190)
var_usr_name = tk.StringVar()
var_usr_name.set(‘example@python.com‘)
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_login():
usr_name = var_usr_name.get()
usr_pwd = 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]:
tk.messagebox.showinfo(title=‘Welcome‘ message=‘How are you? ‘ + usr_name)
else:
tk.messagebox.showerror(message=‘Error your password is wrong try again.‘)
else:
is_sign_up = tk.messagebox.askyesno(‘Welcome‘
‘You have not signed up yet. Sign up today?‘)
if is_sign_up:
usr_sign_up()
def usr_sign_up():
def sign_to_Mofan_Python():
np = new_pwd.get()
npf = new_pwd_confirm.get()
nn = new_name.get()
with open(‘usrs_info.pickle‘ ‘rb‘) as usr_file:
exist_usr_info = pickle.load(usr_file)
if np != npf:
tk.messagebox.showerror(‘Error‘ ‘Password and confirm password must be the same!‘)
elif nn in exist_usr_info:
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_sign_up.destroy()
window_sign_up = tk.Toplevel(window)
window_sign_up.geometry(‘350x200‘)
window_sign_up.title(‘Sign up window‘)
new_name = tk.StringVar()
new_name.set(‘example@python.com‘)
tk.Label(window_sign_up text=‘User name: ‘).place(x=10 y= 10)
entry_new_name = tk.Ent 属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3948 2018-06-04 12:43 login_example.py
----------- --------- ---------- ----- ----
3948 1
- 上一篇:PythonTank
- 下一篇:python外星人入侵.rar
相关资源
- Instant Pygame for Python Game Development How
- Biopython Tutorial
- Think Python 2nd
- 一个小小的表白程序(python)
- Python课堂笔记(高淇400集第一季)
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
川公网安备 51152502000135号
评论
共有 条评论