Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson17-diy3
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
d84c0a56
authored
Jul 15, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
a992d6f4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
107 additions
and
38 deletions
my_window.py
my_window.py
View file @
d84c0a56
import
tkinter
from
tkinter
import
messagebox
import
json
def
register
():
name
=
screen_name
.
get
()
number
=
screen_number
.
get
()
print
(
'您的用户名为:'
+
str
(
name
))
nametext
=
" "
+
str
(
name
)
+
"
\n
"
numbertext
=
" "
+
str
(
number
)
+
"
\n
"
with
open
(
'text.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
tt
:
tt
.
write
(
'用户名:'
+
nametext
)
tt
.
write
(
'密码:'
+
numbertext
)
root
=
tkinter
.
Tk
()
# 创建窗口
root
.
title
(
'注册'
)
# 标题
root
.
geometry
(
'400x320+500+300'
)
# 长×宽+x坐标+y坐标
root
.
resizable
(
height
=
False
,
width
=
False
)
screen_name
=
tkinter
.
Entry
(
root
,
show
=
None
,
font
=
(
'宋体'
,
14
),
bg
=
'light grey'
,
width
=
18
)
# 设置名字窗口
screen_name
.
place
(
x
=
140
,
y
=
80
)
# 名字窗口的坐标
screen_number
=
tkinter
.
Entry
(
root
,
show
=
'*'
,
font
=
(
'宋体'
,
14
),
bg
=
'light grey'
,
width
=
18
)
# 设置密码窗口
screen_number
.
place
(
x
=
140
,
y
=
140
)
# 密码窗口的坐标
screen_numbers
=
tkinter
.
Entry
(
root
,
show
=
'*'
,
font
=
(
'宋体'
,
14
),
bg
=
'light grey'
,
width
=
18
)
# 设置确认密码窗口
screen_numbers
.
place
(
x
=
140
,
y
=
200
)
# 确认密码的坐标
lab
=
tkinter
.
Label
(
root
,
text
=
'您好!请填写注册信息'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
,
width
=
40
,
height
=
2
,
bg
=
"green"
)
# 设置提示
lab
.
place
(
x
=
0
,
y
=
0
)
# 提示坐标
text_name
=
tkinter
.
Label
(
root
,
text
=
'名字:'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
)
# 名字提示
text_name
.
place
(
x
=
50
,
y
=
80
)
# 提示位置
text_number
=
tkinter
.
Label
(
root
,
text
=
'密码:'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
)
# 密码提示
text_number
.
place
(
x
=
50
,
y
=
140
)
# 提示位置
text_numbers
=
tkinter
.
Label
(
root
,
text
=
'确认密码:'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
)
# 确认密码
text_numbers
.
place
(
x
=
30
,
y
=
200
)
# 提示位置
button
=
tkinter
.
Button
(
root
,
text
=
'注册'
,
font
=
((
'宋体'
),
15
),
bg
=
'green'
,
command
=
register
)
# 注册按钮
button
.
place
(
x
=
280
,
y
=
240
)
# 按钮位置
widge
=
tkinter
.
Button
(
root
,
text
=
'登录'
,
font
=
((
'宋体'
),
15
),
bg
=
'green'
,
command
=
register
)
# 登录按钮
widge
.
place
(
x
=
140
,
y
=
240
)
# 按钮位置
root
.
mainloop
()
# 保持运行
\ No newline at end of file
# with open("text.txt","r",encoding="utf-8") as tt:
# info=tt.read()
# user=json.loads(info)
def
login_to_reg
():
# 登录界面转注册界面
app_login
.
root
.
destroy
()
global
app_reg
app_reg
=
My_register
()
app_reg
.
show
()
def
reg_to_login
():
# 注册界面转登录界面
app_reg
.
root
.
destroy
()
global
app_login
app_login
=
My_register
()
app_login
.
show
()
def
register
():
# 注册验证
name
,
passward1
,
passward2
=
app_reg
.
get_input
()
if
name
==
''
or
passward1
==
''
or
passward2
==
''
:
messagebox
.
showerror
(
'身份信息未填写完整!'
)
elif
name
in
user
:
messagebox
.
showerror
(
'该用户名已注册!'
)
elif
passward1
!=
passward2
:
messagebox
.
showerror
(
'密码填写错误!'
)
else
:
user
[
name
]
=
passward1
content
=
json
.
dumps
(
user
)
messagebox
.
showinfo
(
'注册成功!'
)
with
open
(
'text.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
file
.
write
(
content
)
login
.
show
()
def
login
():
pass
class
My_login
():
# 登录界面
def
__init__
(
self
):
self
.
root
=
tkinter
.
Tk
()
# 创建窗口
self
.
root
.
title
(
'登录窗口'
)
# 标题
self
.
root
.
geometry
(
'400x320+500+300'
)
# 长×宽+x坐标+y坐标
self
.
root
.
resizable
(
height
=
False
,
width
=
False
)
def
show
(
self
):
self
.
lab
=
tkinter
.
Label
(
self
.
root
,
text
=
'您好!请填写登录信息'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
,
width
=
40
,
height
=
2
,
bg
=
"green"
)
# 设置提示
self
.
lab
.
place
(
x
=
0
,
y
=
0
)
# 提示坐标
self
.
text_name
=
tkinter
.
Label
(
self
.
root
,
text
=
'名字:'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
)
# 名字提示
self
.
text_name
.
place
(
x
=
50
,
y
=
80
)
# 提示位置
self
.
text_number
=
tkinter
.
Label
(
self
.
root
,
text
=
'密码:'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
)
# 密码提示
self
.
text_number
.
place
(
x
=
50
,
y
=
140
)
# 提示位置
self
.
screen_name
=
tkinter
.
Entry
(
self
.
root
,
show
=
None
,
font
=
(
'宋体'
,
14
),
bg
=
'light grey'
,
width
=
18
)
# 设置名字窗口
self
.
screen_name
.
place
(
x
=
140
,
y
=
80
)
# 名字窗口的坐标
self
.
screen_number
=
tkinter
.
Entry
(
self
.
root
,
show
=
'*'
,
font
=
(
'宋体'
,
14
),
bg
=
'light grey'
,
width
=
18
)
# 设置密码窗口
self
.
screen_number
.
place
(
x
=
140
,
y
=
140
)
# 密码窗口的坐标
self
.
screen_numbers
=
tkinter
.
Entry
(
self
.
root
,
show
=
'*'
,
font
=
(
'宋体'
,
14
),
bg
=
'light grey'
,
width
=
18
)
# 设置确认密码窗口
self
.
screen_numbers
.
place
(
x
=
140
,
y
=
200
)
# 确认密码的坐标
button
=
tkinter
.
Button
(
self
.
root
,
text
=
'注册'
,
font
=
((
'宋体'
),
15
),
bg
=
'light green'
,
command
=
register
)
# 注册按钮
button
.
place
(
x
=
280
,
y
=
240
)
# 按钮位置
widge
=
tkinter
.
Button
(
self
.
root
,
text
=
'登录'
,
font
=
((
'宋体'
),
15
),
bg
=
'light bule'
,
command
=
register
)
# 登录按钮
widge
.
place
(
x
=
140
,
y
=
240
)
# 按钮位置
text_numbers
=
tkinter
.
Label
(
self
.
root
,
text
=
'确认密码:'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
)
# 确认密码
text_numbers
.
place
(
x
=
30
,
y
=
200
)
# 提示位置
self
.
root
.
mainloop
()
# 保持运行
def
get_input
(
self
):
self
.
name
=
self
.
screen_name
.
get
()
self
.
passward1
=
self
.
screen_number
.
get
()
return
self
.
name
,
self
.
passward1
class
My_register
():
def
__init__
(
self
):
self
.
root
=
tkinter
.
Tk
()
# 创建窗口
self
.
root
.
title
(
'登录窗口'
)
# 标题
self
.
root
.
geometry
(
'400x320+500+300'
)
# 长×宽+x坐标+y坐标
self
.
root
.
resizable
(
height
=
False
,
width
=
False
)
def
show
(
self
):
self
.
lab
=
tkinter
.
Label
(
self
.
root
,
text
=
'您好!请填写登录信息'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
,
width
=
40
,
height
=
2
,
bg
=
"green"
)
# 设置提示
self
.
lab
.
place
(
x
=
0
,
y
=
0
)
# 提示坐标
self
.
text_name
=
tkinter
.
Label
(
self
.
root
,
text
=
'名字:'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
)
# 名字提示
self
.
text_name
.
place
(
x
=
50
,
y
=
80
)
# 提示位置
self
.
text_number
=
tkinter
.
Label
(
self
.
root
,
text
=
'密码:'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
)
# 密码提示
self
.
text_number
.
place
(
x
=
50
,
y
=
140
)
# 提示位置
self
.
screen_name
=
tkinter
.
Entry
(
self
.
root
,
show
=
None
,
font
=
(
'宋体'
,
14
),
bg
=
'light grey'
,
width
=
18
)
# 设置名字窗口
self
.
screen_name
.
place
(
x
=
140
,
y
=
80
)
# 名字窗口的坐标
self
.
screen_number
=
tkinter
.
Entry
(
self
.
root
,
show
=
'*'
,
font
=
(
'宋体'
,
14
),
bg
=
'light grey'
,
width
=
18
)
# 设置密码窗口
self
.
screen_number
.
place
(
x
=
140
,
y
=
140
)
# 密码窗口的坐标
self
.
screen_numbers
=
tkinter
.
Entry
(
self
.
root
,
show
=
'*'
,
font
=
(
'宋体'
,
14
),
bg
=
'light grey'
,
width
=
18
)
# 设置确认密码窗口
self
.
screen_numbers
.
place
(
x
=
140
,
y
=
200
)
# 确认密码的坐标
button
=
tkinter
.
Button
(
self
.
root
,
text
=
'提交'
,
font
=
((
'宋体'
),
15
),
bg
=
'light blue'
,
command
=
register
)
# 注册按钮
button
.
place
(
x
=
280
,
y
=
240
)
# 按钮位置
widge
=
tkinter
.
Button
(
self
.
root
,
text
=
'取消'
,
font
=
((
'宋体'
),
15
),
bg
=
'light green'
,
command
=
register
)
# 登录按钮
widge
.
place
(
x
=
140
,
y
=
240
)
# 按钮位置
text_numbers
=
tkinter
.
Label
(
self
.
root
,
text
=
'确认密码:'
,
font
=
(
'宋体'
,
15
),
fg
=
"black"
)
# 确认密码
text_numbers
.
place
(
x
=
30
,
y
=
200
)
# 提示位置
self
.
root
.
mainloop
()
# 保持运行
def
get_input
(
self
):
self
.
name
=
self
.
screen_name
.
get
()
self
.
passward1
=
self
.
screen_number
.
get
()
self
.
passward2
=
self
.
screen_numbers
.
get
()
return
self
.
name
,
self
.
passward1
,
self
.
passward2
app_login
=
My_login
()
app_login
.
show
()
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