Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Administrator
/
level3-lesson21-diy3
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
410a9df1
authored
2 years ago
by
BellCodeEditor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto save
parent
ac70f2c8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
20 deletions
my_cloud.py
my_cloud.py
View file @
410a9df1
import
wordcloud
import
numpy
# import wordcloud
# import numpy
# from PIL import Image
# import jieba
# with open("python二级考试大纲.txt","r",encoding="utf-8") as file:
# p = file.read()
# j_text = jieba.lcut(p)
# p = " ".join(j_text)
# img = Image.open("bell.png")
# data = numpy.array(img)
# stopwords = ["python","的","和"]
# img_colors = wordcloud.ImageColorGenerator(data)
# w = wordcloud.WordCloud(background_color="white",
# font_path="SimHei.ttf",
# mask=data,
# color_func=img_colors,
# max_font_size=60,
# stopwords=stopwords)
# w.generate(p)
# w.to_file("mycloud.png")
from
tkinter
import
filedialog
,
Tk
from
PIL
import
Image
import
jieba
with
open
(
"python二级考试大纲.txt"
,
"r"
,
encoding
=
"utf-8"
)
as
file
:
p
=
file
.
read
()
j_text
=
jieba
.
lcut
(
p
)
p
=
" "
.
join
(
j_text
)
img
=
Image
.
open
(
"bell.png"
)
data
=
numpy
.
array
(
img
)
stopwords
=
[
"python"
,
"的"
,
"和"
]
img_colors
=
wordcloud
.
ImageColorGenerator
(
data
)
w
=
wordcloud
.
WordCloud
(
background_color
=
"white"
,
font_path
=
"SimHei.ttf"
,
mask
=
data
,
color_func
=
img_colors
,
max_font_size
=
60
,
stopwords
=
stopwords
)
w
.
generate
(
p
)
w
.
to_file
(
"mycloud.png"
)
\ No newline at end of file
root
=
Tk
()
root
.
withdraw
()
path
=
filedialog
.
askopenfilenames
(
title
=
'选择图片文件'
,
filetypes
=
[(
'All Files'
,
'*'
)],
initialdir
=
"./"
)
print
(
path
)
\ No newline at end of file
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