Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson3-4-1_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
7f2403d9
authored
3 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
a50ceeec
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
0 deletions
diy.py
diy1.py
diy.py
0 → 100644
View file @
7f2403d9
import
tkinter
from
tkinter
import
messagebox
import
json
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_login
()
app_login
.
show
()
def
register
():
# 注册验证
name
,
passward1
,
passward2
=
app_reg
.
get_input
()
if
name
==
''
or
passward1
==
''
or
passward2
==
''
:
messagebox
.
showwarning
(
'错误'
,
'身份信息未填写完整!'
)
elif
name
in
user
:
messagebox
.
showwarning
(
'错误'
,
'该用户名已注册!'
)
elif
passward1
!=
passward2
:
messagebox
.
showerror
(
'错误'
,
'密码填写错误!'
)
else
:
user
[
name
]
=
passward1
content
=
json
.
dumps
(
user
)
messagebox
.
showwarning
(
'提示'
,
'注册成功!'
)
with
open
(
'text.txt'
,
'w'
,
encoding
=
'utf-8'
)
as
file
:
file
.
write
(
content
)
reg_to_login
()
def
login
():
name
,
passward1
=
app_reg
.
get_input
()
pwd
=
user
.
get
(
name
)
if
pwd
==
passward1
:
messagebox
.
showwarning
(
'提示'
,
'登录成功!'
)
app_reg
.
root
.
destroy
()
else
:
messagebox
.
showwarning
(
'错误'
,
'用户名或密码错误'
)
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
)
# 密码窗口的坐标
button
=
tkinter
.
Button
(
self
.
root
,
text
=
'注册'
,
font
=
((
'宋体'
),
15
),
bg
=
'lightgreen'
,
command
=
login_to_reg
)
# 注册按钮
button
.
place
(
x
=
280
,
y
=
200
)
# 按钮位置
widge
=
tkinter
.
Button
(
self
.
root
,
text
=
'登录'
,
font
=
((
'宋体'
),
15
),
bg
=
'lightblue'
,
command
=
login
)
# 登录按钮
widge
.
place
(
x
=
140
,
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
=
'lightblue'
,
command
=
login_to_reg
)
# 提交按钮
button
.
place
(
x
=
280
,
y
=
240
)
# 按钮位置
widge
=
tkinter
.
Button
(
self
.
root
,
text
=
'取消'
,
font
=
((
'宋体'
),
15
),
bg
=
'lightgreen'
,
command
=
reg_to_login
)
# 取消按钮
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_reg
=
My_login
()
app_reg
.
show
()
This diff is collapsed.
Click to expand it.
diy1.py
0 → 100644
View file @
7f2403d9
import
turtle
r
=
100
screen
=
turtle
.
Screen
()
screen
.
bgcolor
(
"green"
)
pen
=
turtle
.
Pen
()
pen
.
penup
()
pen
.
goto
(
100
,
-
100
)
pen
.
write
(
"你好"
,
font
=
(
"Times"
,
13
,
"normal"
))
pen
.
hideturtle
()
pen1
=
turtle
.
Pen
()
pen1
.
pensize
(
5
)
pen1
.
pencolor
(
"bule"
)
pen1
.
left
(
45
)
pen1
.
forward
(
2
*
r
)
pen1
.
circle
(
r
,
180
)
pen1
.
right
(
90
)
pen1
.
circle
(
r
,
180
)
pen1
.
forward
(
2
*
r
)
pen1
.
hideturtle
()
turtle
.
done
()
This diff is collapsed.
Click to expand it.
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