Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson18-diy1
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
29860d10
authored
Mar 05, 2023
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
145fe74a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
10 deletions
my_app.py
user.txt
my_app.py
View file @
29860d10
import
tkinter
import
tkinter
import
json
from
tkinter
import
messagebox
with
open
(
'user.txt'
,
'r'
,
encoding
=
'utf-8'
)
as
f
:
a
=
f
.
read
()
users
=
json
.
loads
(
a
)
print
(
users
)
def
login_to_reg
():
# 登录界面转注册界面
def
login_to_reg
():
# 登录界面转注册界面
pass
app_login
.
root
.
destroy
()
global
app_reg
app_reg
=
My_register
()
app_reg
.
show
()
def
reg_to_login
():
# 注册界面转登录界面
def
reg_to_login
():
# 注册界面转登录界面
pass
app_reg
.
root
.
destroy
()
global
app_login
app_login
=
My_login
()
app_login
.
show
()
def
register
():
# 注册验证
def
register
():
# 注册验证
pass
name
,
password1
,
password2
=
app_reg
.
get_input
()
if
name
==
''
or
password1
==
''
or
password2
==
''
:
messagebox
.
showwarning
(
'提示'
,
'用户名或密码不能为空'
)
elif
password1
!=
password2
:
messagebox
.
showwarning
(
'提示'
,
'两次密码不一致!'
)
elif
name
in
users
:
messagebox
.
showwarning
(
'提示'
,
'用户名已存在!'
)
else
:
users
[
name
]
=
password1
user1
=
json
.
dumps
(
users
)
messagebox
.
showinfo
(
'提示'
,
'注册成功'
)
print
(
users
)
with
open
(
'user.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
b
:
b
.
write
(
user1
)
app_reg
.
root
.
destroy
()
global
app_login
app_login
=
My_login
()
app_login
.
show
()
def
login
():
# 登录验证
def
login
():
# 登录验证
pass
name
,
password
=
app_login
.
get_input
()
pwd
=
users
.
get
(
name
)
if
pwd
==
password
:
messagebox
.
showinfo
(
'提示'
,
'登陆成功'
)
else
:
messagebox
.
showerror
(
'提示'
,
'用户名或密码错误'
)
class
My_login
():
# 登录窗口
class
My_login
():
# 登录窗口
def
__init__
(
self
):
def
__init__
(
self
):
...
@@ -21,8 +58,8 @@ class My_login(): # 登录窗口
...
@@ -21,8 +58,8 @@ class My_login(): # 登录窗口
def
show
(
self
):
# 登录界面的所有控件
def
show
(
self
):
# 登录界面的所有控件
# Label文本标签,界面提示信息
# Label文本标签,界面提示信息
l
=
tkinter
.
Label
(
self
.
root
,
text
=
'您好!请登录'
,
bg
=
'green'
,
l
=
tkinter
.
Label
(
self
.
root
,
text
=
'您好!请登录'
,
font
=
(
'
宋
体'
,
15
),
width
=
40
,
height
=
2
)
font
=
(
'
楷
体'
,
15
),
width
=
40
,
height
=
2
)
l
.
place
(
x
=
0
,
y
=
0
)
l
.
place
(
x
=
0
,
y
=
0
)
l
=
tkinter
.
Label
(
self
.
root
,
text
=
'用户名:'
,
font
=
(
"宋体"
,
12
),
l
=
tkinter
.
Label
(
self
.
root
,
text
=
'用户名:'
,
font
=
(
"宋体"
,
12
),
fg
=
"black"
)
fg
=
"black"
)
...
@@ -75,7 +112,7 @@ class My_register(): # 注册窗口
...
@@ -75,7 +112,7 @@ class My_register(): # 注册窗口
# Label文本标签,窗口界面文字:用户名、密码、确认密码
# Label文本标签,窗口界面文字:用户名、密码、确认密码
lab
=
tkinter
.
Label
(
self
.
root
,
text
=
'您好!请填写注册信息'
,
lab
=
tkinter
.
Label
(
self
.
root
,
text
=
'您好!请填写注册信息'
,
font
=
(
'
宋体'
,
15
),
fg
=
"black"
,
width
=
40
,
height
=
2
,
bg
=
"green"
)
font
=
(
'
楷体'
,
15
),
fg
=
"black"
,
width
=
40
,
height
=
2
)
lab
.
place
(
x
=
0
,
y
=
0
)
lab
.
place
(
x
=
0
,
y
=
0
)
lab1
=
tkinter
.
Label
(
self
.
root
,
text
=
'用户名:'
,
font
=
(
"宋体"
,
12
),
lab1
=
tkinter
.
Label
(
self
.
root
,
text
=
'用户名:'
,
font
=
(
"宋体"
,
12
),
fg
=
"black"
)
fg
=
"black"
)
...
...
user.txt
View file @
29860d10
{"admin": "123456"}
{"admin": "123456", "a": "a"}
\ No newline at end of file
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment