Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson20-diy4
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
e046199d
authored
Jul 26, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
8e3694b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
10 deletions
code.py
d.py
code.py
View file @
e046199d
import
tkinter
import
tkinter
from
tkinter
import
*
from
tkinter
import
messagebox
from
tkinter
import
messagebox
import
json
import
json
class
Note
():
# 便签、笔记
def
__init__
(
self
):
self
.
root
=
tkinter
.
Tk
()
self
.
root
.
geometry
(
'300x340+1000+200'
)
self
.
root
.
title
(
"我的便签-待办事项"
)
self
.
root
.
resizable
(
width
=
False
,
height
=
False
)
self
.
bg_img
=
tkinter
.
PhotoImage
(
file
=
"bg.png"
)
self
.
box_img
=
tkinter
.
PhotoImage
(
file
=
'box.png'
)
def
show
(
self
):
# 布置窗口界面
# 画布
self
.
canvas
=
tkinter
.
Canvas
(
self
.
root
,
width
=
300
,
height
=
340
)
self
.
canvas
.
create_image
(
0
,
0
,
image
=
self
.
bg_img
,
anchor
=
NW
)
self
.
canvas
.
place
(
x
=
0
,
y
=
0
)
self
.
ent
=
tkinter
.
Entry
(
self
.
root
,
show
=
None
,
font
=
(
'宋体'
,
13
),
bg
=
"snow"
,
width
=
25
)
self
.
ent
.
place
(
x
=
10
,
y
=
310
)
# 按钮
self
.
but
=
tkinter
.
Button
(
self
.
root
,
text
=
'添加'
,
font
=
(
'宋体'
,
12
),
bg
=
"lightblue"
,
width
=
5
,
command
=
self
.
get_info
)
self
.
but
.
place
(
x
=
240
,
y
=
305
)
# 展示所有的文字
self
.
y
=
20
self
.
v
=
0
self
.
val
=
tkinter
.
IntVar
()
for
info
in
alist
:
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
'#FF9900'
)
self
.
select
=
tkinter
.
Radiobutton
(
self
.
canvas
,
image
=
self
.
box_img
,
value
=
self
.
v
,
variable
=
self
.
val
,
width
=
30
,
height
=
15
,
borderwidth
=
1
,
command
=
self
.
move
)
self
.
select
.
place
(
x
=-
25
,
y
=
self
.
y
-
15
)
self
.
v
+=
1
self
.
y
+=
30
def
get_info
(
self
):
info
=
self
.
ent
.
get
()
self
.
ent
.
delete
(
"0"
,
END
)
# 清空输入框
if
info
!=
""
:
alist
.
append
(
info
)
content
=
json
.
dumps
(
users
)
with
open
(
"user.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
file
:
file
.
write
(
content
)
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
'#FF9900'
)
self
.
select
=
tkinter
.
Radiobutton
(
self
.
canvas
,
image
=
self
.
box_img
,
value
=
self
.
v
,
variable
=
self
.
val
,
width
=
30
,
height
=
15
,
borderwidth
=
1
,
command
=
self
.
move
)
self
.
select
.
place
(
x
=-
25
,
y
=
self
.
y
-
15
)
self
.
v
+=
1
self
.
y
+=
30
def
move
(
self
):
num
=
self
.
val
.
get
()
alist
.
pop
(
num
)
content
=
json
.
dumps
(
users
)
with
open
(
"user.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
file
:
file
.
write
(
content
)
self
.
canvas
.
destroy
()
app
.
show
()
with
open
(
"user.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
with
open
(
"user.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
info
=
f
.
read
()
info
=
f
.
read
()
users
=
json
.
loads
(
info
)
users
=
json
.
loads
(
info
)
...
@@ -27,19 +84,30 @@ def register(): # 注册验证
...
@@ -27,19 +84,30 @@ def register(): # 注册验证
elif
password1
!=
password2
:
elif
password1
!=
password2
:
messagebox
.
showwarning
(
"错误"
,
"两次密码不一致!"
)
messagebox
.
showwarning
(
"错误"
,
"两次密码不一致!"
)
else
:
else
:
user_info
=
{}
user_info
[
'password'
]
=
password1
user_info
[
'event'
]
=
[
'提示1:可以从输入框添加新任务'
,
'提示2:点击最前面的选择框,表示任务完成'
]
users
[
name
]
=
password1
users
[
name
]
=
password1
content
=
json
.
dumps
(
users
)
content
=
json
.
dumps
(
users
)
with
open
(
"user.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
file
:
# "w"每次写入都覆盖原来的内容
with
open
(
"user.txt"
,
"w"
,
encoding
=
"utf-8"
)
as
file
:
# "w"每次写入都覆盖原来的内容
file
.
write
(
content
)
file
.
write
(
content
)
# 注册成功,跳往登陆界面
# 注册成功,跳往登陆界面
messagebox
.
showinfo
(
"成功"
,
"注册成功"
)
messagebox
.
showinfo
(
"成功"
,
"注册成功"
)
reg_to_login
()
reg_to_login
()
def
login
():
# 登录验证
def
login
():
# 登录验证
global
app
,
alist
name
,
password
=
app_login
.
get_input
()
name
,
password
=
app_login
.
get_input
()
pwd
=
users
.
get
(
name
)
user_name
=
users
.
get
(
name
)
if
pwd
==
password
:
if
user_name
!=
None
and
user_name
[
'password'
]
==
password
:
alist
=
users
[
name
][
'event'
]
messagebox
.
showinfo
(
"成功"
,
"登录成功"
)
messagebox
.
showinfo
(
"成功"
,
"登录成功"
)
app_login
.
root
.
destroy
()
app
=
Note
()
app
.
show
()
app
.
root
.
mainloop
()
else
:
else
:
messagebox
.
showwarning
(
"错误"
,
"用户名或密码错误!"
)
messagebox
.
showwarning
(
"错误"
,
"用户名或密码错误!"
)
...
@@ -48,7 +116,8 @@ class My_login(): # 登录窗口
...
@@ -48,7 +116,8 @@ class My_login(): # 登录窗口
self
.
root
=
tkinter
.
Tk
()
self
.
root
=
tkinter
.
Tk
()
self
.
root
.
title
(
"登录窗口"
)
self
.
root
.
title
(
"登录窗口"
)
self
.
root
.
geometry
(
'400x300+500+300'
)
self
.
root
.
geometry
(
'400x300+500+300'
)
self
.
root
.
resizable
(
width
=
False
,
height
=
False
)
# True可以拉伸,False不能拉伸
self
.
root
.
resizable
(
width
=
False
,
height
=
False
)
# True可以拉伸,False不能拉伸
def
show
(
self
):
# 登录界面的所有控件
def
show
(
self
):
# 登录界面的所有控件
# Label文本标签,界面提示信息
# Label文本标签,界面提示信息
...
@@ -77,9 +146,11 @@ class My_login(): # 登录窗口
...
@@ -77,9 +146,11 @@ class My_login(): # 登录窗口
button2
=
tkinter
.
Button
(
self
.
root
,
text
=
'注册'
,
bg
=
"lightgreen"
,
button2
=
tkinter
.
Button
(
self
.
root
,
text
=
'注册'
,
bg
=
"lightgreen"
,
fg
=
"black"
,
width
=
15
,
command
=
login_to_reg
)
fg
=
"black"
,
width
=
15
,
command
=
login_to_reg
)
button2
.
place
(
x
=
230
,
y
=
220
)
button2
.
place
(
x
=
230
,
y
=
220
)
self
.
root
.
mainloop
()
# 进入消息循环,监听事件
self
.
root
.
mainloop
()
# 进入消息循环,监听事件
def
get_input
(
self
):
# 获取输入的用户名、密码
def
get_input
(
self
):
# 获取输入的用户名、密码
self
.
name
=
self
.
e1
.
get
()
self
.
name
=
self
.
e1
.
get
()
self
.
password
=
self
.
e2
.
get
()
self
.
password
=
self
.
e2
.
get
()
return
self
.
name
,
self
.
password
return
self
.
name
,
self
.
password
...
@@ -89,7 +160,8 @@ class My_register(): # 注册窗口
...
@@ -89,7 +160,8 @@ class My_register(): # 注册窗口
self
.
root
=
tkinter
.
Tk
()
self
.
root
=
tkinter
.
Tk
()
self
.
root
.
title
(
"注册窗口"
)
self
.
root
.
title
(
"注册窗口"
)
self
.
root
.
geometry
(
'400x320+500+300'
)
self
.
root
.
geometry
(
'400x320+500+300'
)
self
.
root
.
resizable
(
width
=
False
,
height
=
False
)
# True可以拉伸,False不能拉伸
self
.
root
.
resizable
(
width
=
False
,
height
=
False
)
# True可以拉伸,False不能拉伸
def
show
(
self
):
# 注册界面的所有控件
def
show
(
self
):
# 注册界面的所有控件
# 用户名、密码、确认密码输入框
# 用户名、密码、确认密码输入框
...
@@ -127,7 +199,8 @@ class My_register(): # 注册窗口
...
@@ -127,7 +199,8 @@ class My_register(): # 注册窗口
# 进入消息循环
# 进入消息循环
self
.
root
.
mainloop
()
self
.
root
.
mainloop
()
def
get_input
(
self
):
# 获取提交的注册信息
def
get_input
(
self
):
# 获取提交的注册信息
self
.
name
=
self
.
e1
.
get
()
self
.
name
=
self
.
e1
.
get
()
self
.
password1
=
self
.
e2
.
get
()
self
.
password1
=
self
.
e2
.
get
()
self
.
password2
=
self
.
e3
.
get
()
self
.
password2
=
self
.
e3
.
get
()
...
...
d.py
View file @
e046199d
...
@@ -207,5 +207,4 @@ class My_register(): # 注册窗口
...
@@ -207,5 +207,4 @@ class My_register(): # 注册窗口
return
self
.
name
,
self
.
password1
,
self
.
password2
return
self
.
name
,
self
.
password1
,
self
.
password2
app_login
=
My_login
()
app_login
=
My_login
()
app_login
.
show
()
app_login
.
show
()
\ 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