# -*- coding: utf-8 -*-
# @Time : 2020/1/15 14:49
# @Author : LiuZe
# @File : tkinter_2.py
# @Software : PyCharm
from tkinter import *
from tkinter import messagebox
root=Tk()
root.title('某某登录系统')
Label(root,text='账号:').grid(row=0)
Label(root,text='密码:').grid(row=1)
e1=Entry(root)
e2=Entry(root,show='*')
e1.grid(row=0,column=1,padx=10,pady=5)
e2.grid(row=1,column=1,padx=10,pady=5)
def show_1():
root_1=Tk()
root_1.title('注册')
Label(root_1,text='用户名:').grid(row=0)
Label(root_1,text='密码:').grid(row=1)
Label(root_1,text='再一次输入密码:').grid(row=2)
e_1=Entry(root_1)
e_2=Entry(root_1,show='*')
e_3=Entry(root_1,show='*')
e_1.grid(row=0,column=1,padx=10,pady=5)
e_2.grid(row=1,column=1,padx=10,pady=5)
e_3.grid(row=2,column=1,padx=10,pady=5)
def show_2():
if e_2.get()==e_3.get():
with open('./1.txt','a') as f:
f.writelines(str(e_1.get())+','+str(e_2.get()))
f.writelines('\n')
exit()
else:
bool_1=messagebox.askquestion('出错','你两次输入的密码不相同,是否重新输入!')
if bool_1:
pass
else:
exit()
Button(root_1,text='保存',width=10,command=show_2).grid(row=3,column=0,sticky=W,padx=10,pady=5)
def show_3():
list_3=[]
bool_1=False
with open('./1.txt','r') as f:
string_1=f.read()
list_1=string_1.split('\n')
for ch in list_1:
list_2=ch.split(',')
list_3.append(list_2)
for ch_1 in list_3:
if len(ch_1)!=0 and e1.get()==ch_1[0] and e2.get()==ch_1[1]:
print('登录成功!')
bool_1=True
break
if(bool_1==False):
print('你的输入有问题!')
Button(root,text='注册',width=10,command=show_1).grid(row=3,column=0,sticky=W,padx=10,pady=5)
Button(root,text='登录',width=10,command=show_3).grid(row=3,column=1,sticky=W,padx=10,pady=5)
mainloop()
在运行这个登录系统时,首先要进行注册:
如下图: