Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson19-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
08fb9571
authored
Nov 07, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
39bdb55e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
109 additions
and
2 deletions
client.py
diy1.py
diy2.py
diy3.py
diy4.py
client.py
View file @
08fb9571
import
tkinter
from
tkinter
import
*
alist
=
[
"星期六下午打篮球"
,
"星期天下午和小美一起看电影"
,
"12月18日给蒂法过生日"
,
"12.24送妈妈圣诞礼物"
]
...
...
@@ -8,9 +9,29 @@ class Note(): # 便签、笔记
self
.
root
=
tkinter
.
Tk
()
self
.
root
.
geometry
(
'300x340+1000+200'
)
self
.
root
.
title
(
"我的便签-待办事项"
)
self
.
root
.
resizable
(
width
=
False
,
height
=
False
)
self
.
root
.
resizable
(
width
=
False
,
height
=
False
)
self
.
bg_image
=
tkinter
.
PhotoImage
(
file
=
"bg.png"
)
#载入图片
def
show
(
self
):
# 布置窗口界面
#创建画布Canvas
"""
画在哪里---屏幕上,其他画布上
画布的宽
画布的高
背景颜色
"""
self
.
canvas
=
tkinter
.
Canvas
(
self
.
root
,
width
=
300
,
height
=
340
,
bg
=
"lightblue"
)
#将图片放在画布上create_image()
"""
x坐标
y坐标
image图片
anchor对齐方式---NW
"""
self
.
canvas
.
create_image
(
0
,
0
,
image
=
self
.
bg_image
,
anchor
=
NW
)
#布局
self
.
canvas
.
place
(
x
=
0
,
y
=
0
)
# 输入框
self
.
ent
=
tkinter
.
Entry
(
self
.
root
,
show
=
None
,
font
=
(
'宋体'
,
13
),
bg
=
"snow"
,
width
=
25
)
...
...
@@ -19,10 +40,23 @@ class Note(): # 便签、笔记
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
for
info
in
alist
:
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
"#FF9900"
)
self
.
y
+=
30
def
get_info
(
self
):
pass
#获取输入框中的内容
info
=
self
.
ent
.
get
()
if
not
(
info
in
alist
):
if
info
!=
""
:
alist
.
append
(
info
)
self
.
canvas
.
create_text
(
40
,
self
.
y
,
text
=
info
,
font
=
(
"宋体"
,
11
),
anchor
=
W
,
fill
=
"#FF9900"
)
self
.
y
+=
30
#delete方法--清空输入框
self
.
ent
.
delete
(
"0"
,
END
)
app
=
Note
()
app
.
show
()
app
.
root
.
mainloop
()
\ No newline at end of file
diy1.py
0 → 100644
View file @
08fb9571
#快速排序
def
quick_sort
(
data
):
"""
data---一个列表
"""
#边界条件
if
len
(
data
)
>
1
:
#选取基准值(分界值)
mid
=
data
[
len
(
data
)
//
2
]
#定义左右两侧的列表
left
,
right
=
[],[]
#先将基准值从原始数据中删除
data
.
remove
(
mid
)
for
i
in
data
:
if
i
>=
mid
:
right
.
append
(
i
)
else
:
left
.
append
(
i
)
return
quick_sort
(
left
)
+
[
mid
]
+
quick_sort
(
right
)
else
:
return
data
li
=
[
3
,
8
,
2
,
4
,
0
,
9
,
6
,
1
,
7
,
5
]
print
(
quick_sort
(
li
))
diy2.py
0 → 100644
View file @
08fb9571
import
random
#定义列表
list
=
[]
for
i
in
range
(
100
):
num
=
random
.
randint
(
1
,
50
)
list
.
append
(
num
)
#显示在屏幕上
print
(
list
)
\ No newline at end of file
diy3.py
0 → 100644
View file @
08fb9571
# list=[]
# for i in range(10):
# list.append(i)
#列表解析式的基本格式[表达式 条件1 条件2]
list
=
[(
x
+
1
,
y
+
1
)
for
x
in
range
(
5
)
for
y
in
range
(
5
)]
# list=[1 for x in range(5)]
"""
list=[]
for i in range(10):
if i**2<50
list.append(i**2)
"""
print
(
list
)
\ No newline at end of file
diy4.py
0 → 100644
View file @
08fb9571
#使用列表解析式生成100个数组成的列表
import
random
list
=
[
random
.
randint
(
1
,
50
)
for
i
in
range
(
100
)]
#定义列表---计数统计
count
=
[
0
for
i
in
range
(
len
(
list
))]
#遍历获取每一个元素,并记录到count列表中
for
i
in
list
:
count
[
i
]
+=
1
#遍历完后清空列表
list
.
clear
()
for
i
,
j
in
enumerate
(
count
):
for
k
in
range
(
j
):
#将数据中的计数次数进行循环
list
.
append
(
i
)
print
(
list
)
\ 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