Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
bellcode
/
lesson6-4
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
9c38391f
authored
Oct 23, 2021
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
07ef43ed
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
121 additions
and
0 deletions
diy.py
diy1.py
diy2.py
diy3.py
diy4.py
diy.py
View file @
9c38391f
...
@@ -3,5 +3,8 @@
...
@@ -3,5 +3,8 @@
# 省略繁杂情节,刘关张三人一起冲入战场,围攻吕布:
# 省略繁杂情节,刘关张三人一起冲入战场,围攻吕布:
a
=
[
'吕布'
]
a
=
[
'吕布'
]
b
=
[
'袁术'
,
'公孙瓒'
,
'关羽'
,
'张飞'
,
'刘备'
,
'曹操'
]
b
=
[
'袁术'
,
'公孙瓒'
,
'关羽'
,
'张飞'
,
'刘备'
,
'曹操'
]
c
=
b
[
2
:
5
]
a
.
extend
(
c
)
print
(
a
)
diy1.py
0 → 100644
View file @
9c38391f
numbers
=
[
12
,
15
,
19
,
22
,
28
,
31
]
even
=
[]
old
=
[]
while
len
(
numbers
)
>
0
:
number
=
numbers
.
pop
()
if
(
number
%
2
==
0
):
even
.
append
(
number
)
else
:
old
.
append
(
number
)
print
(
even
)
print
(
old
)
diy2.py
0 → 100644
View file @
9c38391f
i
=
2
while
i
<
200
:
j
=
2
while
(
j
<=
(
i
/
j
)):
if
not
(
i
%
j
):
break
j
+=
1
if
(
j
>
i
/
j
):
print
(
i
)
i
+=
1
print
(
"good bye"
)
\ No newline at end of file
diy3.py
0 → 100644
View file @
9c38391f
from
tkinter
import
*
import
hashlib
import
time
LOG_LINE_NUM
=
0
class
MY_GUI
():
def
__init__
(
self
,
init_window_name
):
self
.
init_window_name
=
init_window_name
#设置窗口
def
set_init_window
(
self
):
self
.
init_window_name
.
title
(
"文本处理工具_v1.2"
)
#窗口名
#self.init_window_name.geometry('320x160+10+10') #290 160为窗口大小,+10 +10 定义窗口弹出时的默认展示位置
self
.
init_window_name
.
geometry
(
'1068x681+10+10'
)
#self.init_window_name["bg"] = "pink" #窗口背景色,其他背景色见:blog.csdn.net/chl0000/article/details/7657887
#self.init_window_name.attributes("-alpha",0.9) #虚化,值越小虚化程度越高
#标签
self
.
init_data_label
=
Label
(
self
.
init_window_name
,
text
=
"待处理数据"
)
self
.
init_data_label
.
grid
(
row
=
0
,
column
=
0
)
self
.
result_data_label
=
Label
(
self
.
init_window_name
,
text
=
"输出结果"
)
self
.
result_data_label
.
grid
(
row
=
0
,
column
=
12
)
self
.
log_label
=
Label
(
self
.
init_window_name
,
text
=
"日志"
)
self
.
log_label
.
grid
(
row
=
12
,
column
=
0
)
#文本框
self
.
init_data_Text
=
Text
(
self
.
init_window_name
,
width
=
67
,
height
=
35
)
#原始数据录入框
self
.
init_data_Text
.
grid
(
row
=
1
,
column
=
0
,
rowspan
=
10
,
columnspan
=
10
)
self
.
result_data_Text
=
Text
(
self
.
init_window_name
,
width
=
70
,
height
=
49
)
#处理结果展示
self
.
result_data_Text
.
grid
(
row
=
1
,
column
=
12
,
rowspan
=
15
,
columnspan
=
10
)
self
.
log_data_Text
=
Text
(
self
.
init_window_name
,
width
=
66
,
height
=
9
)
# 日志框
self
.
log_data_Text
.
grid
(
row
=
13
,
column
=
0
,
columnspan
=
10
)
#按钮
self
.
str_trans_to_md5_button
=
Button
(
self
.
init_window_name
,
text
=
"字符串转MD5"
,
bg
=
"lightblue"
,
width
=
10
,
command
=
self
.
str_trans_to_md5
)
# 调用内部方法 加()为直接调用
self
.
str_trans_to_md5_button
.
grid
(
row
=
1
,
column
=
11
)
#功能函数
def
str_trans_to_md5
(
self
):
src
=
self
.
init_data_Text
.
get
(
1.0
,
END
)
.
strip
()
.
replace
(
"
\n
"
,
""
)
.
encode
()
#print("src =",src)
if
src
:
try
:
myMd5
=
hashlib
.
md5
()
myMd5
.
update
(
src
)
myMd5_Digest
=
myMd5
.
hexdigest
()
#print(myMd5_Digest)
#输出到界面
self
.
result_data_Text
.
delete
(
1.0
,
END
)
self
.
result_data_Text
.
insert
(
1.0
,
myMd5_Digest
)
self
.
write_log_to_Text
(
"INFO:str_trans_to_md5 success"
)
except
:
self
.
result_data_Text
.
delete
(
1.0
,
END
)
self
.
result_data_Text
.
insert
(
1.0
,
"字符串转MD5失败"
)
else
:
self
.
write_log_to_Text
(
"ERROR:str_trans_to_md5 failed"
)
#获取当前时间
def
get_current_time
(
self
):
current_time
=
time
.
strftime
(
'
%
Y-
%
m-
%
d
%
H:
%
M:
%
S'
,
time
.
localtime
(
time
.
time
()))
return
current_time
#日志动态打印
def
write_log_to_Text
(
self
,
logmsg
):
global
LOG_LINE_NUM
current_time
=
self
.
get_current_time
()
logmsg_in
=
str
(
current_time
)
+
" "
+
str
(
logmsg
)
+
"
\n
"
#换行
if
LOG_LINE_NUM
<=
7
:
self
.
log_data_Text
.
insert
(
END
,
logmsg_in
)
LOG_LINE_NUM
=
LOG_LINE_NUM
+
1
else
:
self
.
log_data_Text
.
delete
(
1.0
,
2.0
)
self
.
log_data_Text
.
insert
(
END
,
logmsg_in
)
def
gui_start
():
init_window
=
Tk
()
#实例化出一个父窗口
ZMJ_PORTAL
=
MY_GUI
(
init_window
)
# 设置根窗口默认属性
ZMJ_PORTAL
.
set_init_window
()
init_window
.
mainloop
()
#父窗口进入事件循环,可以理解为保持窗口运行,否则界面不展示
gui_start
()
\ No newline at end of file
diy4.py
0 → 100644
View file @
9c38391f
for
i
in
range
(
1
,
10
):
#行
for
j
in
range
(
1
,
i
+
1
):
#列
print
(
j
,
"x"
,
i
,
"="
,
j
*
i
,
end
=
" "
)
print
()
\ 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