风月词云
from wordcloud import WordCloud
import numpy as np
from PIL import Image
print("请在D盘下的词云文本中输入你想要的关键词")
x=input("是否添加好关键词,输入Y或y确认")
if x=='y'or x=='Y':
path1="D:\\fonts\\msyh.ttc"
txt=open("D:\\词云文本.txt","rt",encoding="utf-8")
text=txt.readline()
mask=np.array(Image.open("D:\\词云背景图2.png"))
wcd=WordCloud(background_color="white",repeat=True,max_words=200,height=480,\
width=854,max_font_size=50,font_path=path1,mask=mask,contour_width=2,\
contour_color="red")
wcd.generate(text)
wcd.to_file("词云图.png")
else:exit(1)