import wordcloud
font = 'C:\Windows\Fonts\ITCEDSCR.TTF'
file = open('D:\python1\pythonProject\copypoetry.txt',encoding='UTF-8')
string = str(file.read())
file.close()
w = wordcloud.WordCloud(font_path=font,max_words=500,max_font_size=40,backgroud_color='white')
w.generate(string)
w.to_file('ss.png')
下面的是运行结果
D:\python1\pythonProject\venv\Scripts\python.exe D:/python1/pythonProject/poetry.py
Building prefix dict from the default dictionary ...
Loading model from cache C:\Users\H1831\AppData\Local\Temp\jieba.cache
Loading model cost 1.261 seconds.
Prefix dict has been built successfully.
Process finished with exit code 0