Commit f47c33ae by BellCodeEditor

auto save

parent 6b1fbc15
from tkinter import filedialog,Tk
path=filedialog.askopenfilenames(title="周日",filetypes=[('All Files',"*")],initialdir="./")
print(path)
\ No newline at end of file
#wordcloud词云模块
#pillow图像处理模块PIL---Image图片处理模块
from PIL import Image
import numpy as np
import wordcloud import wordcloud
import jieba
#打开图片
img=Image.open("bell.png")
#print(img)
value=np.array(img)
#print(value)
#
img_colors=wordcloud.ImageColorGenerator(value)#ImageColorGenertator(颜色数组)-->颜色对象
print(img_colors)
#打开python二级文件
with open("python二级考试大纲.txt","r",encoding="utf-8") as file:
a=file.read()
g=jieba.lcut_for_search(a)#jieba模块lcut()得到的是列表
#拼接列表中的数据
a="".join(g)
stopwords=["Python","必选","可选","基础的"]
#创建词云对象
w=wordcloud.WordCloud(background_color="white",font_path="C:\\Windows\\Fonts\\msyh.ttc",mask=value,color_func=img_colors,
stopwords=stopwords,max_font_size=100)
'''
background_color背景颜色
font_path字体路径
mask模式,当不赋值的时候,以二维坐标进行绘制。当赋值后,以此为参考。全白位置不绘制
color_func 设置文字颜色
stopwords 屏蔽文字信息
'''
#generate("内容")将内容展示出来
w.generate(a)
#生成词云图片
w.to_file("myclond.png")
mycloud.png

74.6 KB

list=["我们","是","中国","新时代","少年"]
list=["我们","是","中国","新时代","少年"]
#格式:--->"连接符".join(列表)
# s="".join(list)
# s=" ".join(list)
s="*".join(list)
print(s)
\ No newline at end of file
# 匿名函数基本格式
# 匿名函数基本格式
#lambda 参数1,参数2,参数3,...:表达式
#定义函数计算3个数的和
"""
def jisuan(a,b,c):
return a+b+c
print(jisuan(1,2,3))
d=lambda a,b,c:a+b+c
print(d(1,2,3))
"""
b=lambda x:"偶数" if x % 2==0 else "奇数"
print(b(4))
#pillow图像处理模块PIL---Image图片处理模块
#pillow图像处理模块PIL---Image图片处理模块
from PIL import Image
import numpy as np
#打开图片
img=Image.open("6x2.png")
print(img)
value=np.array(img)
print(value)
#用户界面tkinter
#用户界面tkinter
import tkinter
#创建窗口
root=tkinter.Tk()
#给窗口起个名字title()
root.title("注册")
#设置窗口大小和位置400x320----geometry("宽度x高度+x坐标+y坐标")
root.geometry("400x320+500+200")
root.resizable(width=False,height=False)
def pos():
name=e1.get()
pwd=e2.get()
print("用户名是:",name,"密码是:",pwd)
#单行文本输入框Entry(screen,font)
e1=tkinter.Entry(root,font=("宋体",14),fg="black",bg="light yellow",width=18)
e2=tkinter.Entry(root,show="*",font=("宋体",14),fg="black",bg="light green",width=18)
e3=tkinter.Entry(root,show="#",font=("宋体",14),fg="black",bg="light grey",width=18)
#布局
e1.place(x=140,y=80)
e2.place(x=140,y=140)
e3.place(x=140,y=200)
"""
screen----将单行输入框创建在哪个界面上
font---字体类型和大小
show---显示输入框中内容的格式none
bg---背景
fg-字体颜色
width--输入框中最多输入字符数量
"""
#标签页Label(screen,text,font)
"""
screen---展示界面
text---展示内容
font---字体类型和大小
fg---字体颜色
bg---背景颜色
width
height
"""
l1=tkinter.Label(root,text="请完善注册信息",font=("宋体",14),fg="black",bg="green",width=40,height=2)
l2=tkinter.Label(root,text="用户名",font=("宋体",14),fg="black")
l3=tkinter.Label(root,text="密码",font=("宋体",14),fg="black")
l4=tkinter.Label(root,text="确认密码",font=("宋体",14),fg="black")
#布局
l1.place(x=0,y=0)
l2.place(x=5,y=80)
l3.place(x=5,y=140)
l4.place(x=5,y=200)
#按钮Button(root)
button1=tkinter.Button(root,text="提交",bg="green",command=pos)
#布局
button1.place(x=150,y=250)
#保存窗口,循环监听事件
root.mainloop()
\ No newline at end of file
import jieba
import jieba
"""
是将中文拆解成词语的一个优秀的第三方模块
pip install jieba
3种模式:
全模式 cut(一段字符串)
精确模式 lcut(一段字符串)
搜索引擎模式 lcut_for_search(一段字符串)
得到的是列表
"""
text="中华人民共和国是一个伟大国家"
w=jieba.lcut(text)
print(w)
f=jieba.cut(text)
print(f)
g=jieba.lcut_for_search(text)
print(g)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment