Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson17-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
2a4e6629
authored
May 07, 2022
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
save project
parent
77e28211
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
19 deletions
my_window.py
my_window.py
View file @
2a4e6629
...
@@ -3,9 +3,6 @@ from tkinter import *
...
@@ -3,9 +3,6 @@ from tkinter import *
from
tkinter
import
messagebox
from
tkinter
import
messagebox
import
json
import
json
alist
=
[
"星期六下午打篮球"
,
"星期天下午和小美一起看电影"
,
"12月18日给蒂法过生日"
,
"12.24送妈妈圣诞礼物"
]
class
Note
():
# 便签、笔记
class
Note
():
# 便签、笔记
def
__init__
(
self
):
def
__init__
(
self
):
self
.
root
=
tkinter
.
Tk
()
self
.
root
=
tkinter
.
Tk
()
...
@@ -35,6 +32,7 @@ class Note(): # 便签、笔记
...
@@ -35,6 +32,7 @@ class Note(): # 便签、笔记
for
info
in
alist
:
for
info
in
alist
:
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
'#FF9900'
)
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
'#FF9900'
)
# 单选框组件
self
.
select
=
tkinter
.
Radiobutton
(
self
.
canvas
,
image
=
self
.
box
,
self
.
select
=
tkinter
.
Radiobutton
(
self
.
canvas
,
image
=
self
.
box
,
value
=
self
.
val
,
variable
=
self
.
v
,
width
=
25
,
height
=
15
,
value
=
self
.
val
,
variable
=
self
.
v
,
width
=
25
,
height
=
15
,
borderwidth
=
0
,
command
=
self
.
remove
)
borderwidth
=
0
,
command
=
self
.
remove
)
...
@@ -42,26 +40,36 @@ class Note(): # 便签、笔记
...
@@ -42,26 +40,36 @@ class Note(): # 便签、笔记
self
.
val
+=
1
self
.
val
+=
1
self
.
y
+=
30
self
.
y
+=
30
def
remove
(
self
):
def
remove
(
self
):
# 清除选中的任务事件
num
=
self
.
v
.
get
()
num
=
self
.
v
.
get
()
alist
.
pop
(
num
)
alist
.
pop
(
num
)
# 更新用户待办事项
content
=
json
.
dumps
(
users
)
with
open
(
"user.txt"
,
"w"
,
encoding
=
"utf8"
)
as
file
:
file
.
write
(
content
)
# 重新渲染便签界面
self
.
canvas
.
destroy
()
self
.
canvas
.
destroy
()
app
.
show
()
app
.
show
()
def
get_info
(
self
):
def
get_info
(
self
):
# 获取用户添加的新事件
info
=
self
.
ent
.
get
()
info
=
self
.
ent
.
get
()
self
.
ent
.
delete
(
"0"
,
END
)
self
.
ent
.
delete
(
"0"
,
END
)
if
info
!=
""
:
if
info
!=
""
:
alist
.
append
(
info
)
alist
.
append
(
info
)
# 更新用户待办事项
content
=
json
.
dumps
(
users
)
with
open
(
"user.txt"
,
"w"
,
encoding
=
"utf8"
)
as
file
:
file
.
write
(
content
)
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
'#FF9900'
)
anchor
=
W
,
fill
=
'#FF9900'
)
# 单选框组件
self
.
select
=
tkinter
.
Radiobutton
(
self
.
canvas
,
image
=
self
.
box
,
self
.
select
=
tkinter
.
Radiobutton
(
self
.
canvas
,
image
=
self
.
box
,
value
=
self
.
val
,
variable
=
self
.
v
,
width
=
25
,
height
=
15
,
value
=
self
.
val
,
variable
=
self
.
v
,
width
=
25
,
height
=
15
,
borderwidth
=
0
,
command
=
self
.
remove
)
borderwidth
=
0
,
command
=
self
.
remove
)
self
.
select
.
place
(
x
=-
20
,
y
=
self
.
y
-
10
)
self
.
select
.
place
(
x
=-
20
,
y
=
self
.
y
-
10
)
self
.
val
+=
1
self
.
val
+=
1
self
.
y
+=
30
self
.
y
+=
30
# 读取用户信息
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
)
...
@@ -86,8 +94,12 @@ def register(): # 注册验证
...
@@ -86,8 +94,12 @@ def register(): # 注册验证
messagebox
.
showwarning
(
"错误"
,
"用户名已经存在!"
)
messagebox
.
showwarning
(
"错误"
,
"用户名已经存在!"
)
elif
password1
!=
password2
:
elif
password1
!=
password2
:
messagebox
.
showwarning
(
"错误"
,
"两次密码不一致!"
)
messagebox
.
showwarning
(
"错误"
,
"两次密码不一致!"
)
else
:
else
:
# 通过验证
users
[
name
]
=
password1
user_info
=
{}
user_info
[
"password"
]
=
password1
user_info
[
"event"
]
=
[
"提示1:可以从输入框添加新任务"
,
"提示2:点击前面选择框,表示任务完成"
]
users
[
name
]
=
user_info
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
)
...
@@ -96,10 +108,12 @@ def register(): # 注册验证
...
@@ -96,10 +108,12 @@ def register(): # 注册验证
reg_to_login
()
reg_to_login
()
def
login
():
# 登录验证
def
login
():
# 登录验证
global
app
global
app
,
alist
name
,
password
=
app_login
.
get_input
()
name
,
password
=
app_login
.
get_input
()
pwd
=
users
.
get
(
name
)
# 验证用户名、密码是否正确
if
pwd
==
password
:
user_name
=
users
.
get
(
name
)
if
user_name
!=
None
and
user_name
[
"password"
]
==
password
:
alist
=
users
[
name
][
"event"
]
app_login
.
root
.
destroy
()
app_login
.
root
.
destroy
()
app
=
Note
()
app
=
Note
()
app
.
show
()
app
.
show
()
...
@@ -133,8 +147,7 @@ class My_login(): # 登录窗口
...
@@ -133,8 +147,7 @@ class My_login(): # 登录窗口
width
=
18
)
# 显示成密文形式
width
=
18
)
# 显示成密文形式
self
.
e1
.
place
(
x
=
120
,
y
=
80
)
self
.
e1
.
place
(
x
=
120
,
y
=
80
)
self
.
e2
.
place
(
x
=
120
,
y
=
140
)
self
.
e2
.
place
(
x
=
120
,
y
=
140
)
# 登录、注册按钮
# 登录、注册按钮
button1
=
tkinter
.
Button
(
self
.
root
,
text
=
'登录'
,
bg
=
"lightblue"
,
button1
=
tkinter
.
Button
(
self
.
root
,
text
=
'登录'
,
bg
=
"lightblue"
,
fg
=
"black"
,
width
=
15
,
command
=
login
)
fg
=
"black"
,
width
=
15
,
command
=
login
)
button1
.
place
(
x
=
60
,
y
=
220
)
button1
.
place
(
x
=
60
,
y
=
220
)
...
@@ -199,9 +212,3 @@ class My_register(): # 注册窗口
...
@@ -199,9 +212,3 @@ class My_register(): # 注册窗口
app_login
=
My_login
()
app_login
=
My_login
()
app_login
.
show
()
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