# 来写一个窗口
import PIL
import tkinter as ek
from tkinter.filedialog import askopenfilename
from PIL import Image, ImageTk
import base64
class da_fen():
mywindow = ek.Tk()
mywindow.geometry("888x666")
mywindow.title("你钉起来真好听")
# 修改背景色
canvas = ek.Canvas(mywindow, width=888,height=666,bg="#9400D3")
canvas.pack()
def start(self):
# 按钮: 打开文件
ek.Button(self.mywindow,text="打开文件",command=self.show_picture).place(x=50,y=150)
# 按钮: 颜值识别
ek.Button(self.mywindow,text="颜值识别",command=self.show_picture).place(x=50,y=250)
# 按钮: 退出软件
ek.Button(self.mywindow,text="退出软件",command=self.show_picture).place(x=50,y=350)
# 原图 标签:Label
ek.Label(self.mywindow,text="原图").place(x=420,y=50)
ek.Label(self.mywindow,text="性别").place(x=680,y=150)
ek.Label(self.mywindow,text="颜值").place(x=680,y=250)
ek.Label(self.mywindow,text="年龄").place(x=680,y=350)
# 显示图框
self.label_img = ek.Label(self.mywindow)
# 显示图框背景
self.cv_img = ek.Canvas(self.mywindow, bg='white',width=270,height=270)
# 显示图框边框
self.cv_img.create_rectangle(8,8,260,260,width=1,outline="red")
# 设置位置
self.cv_img.place(x=265,y=150)
self.label_img.place(x=265,y=150)
self.text1 = ek.Text(self.mywindow, font=15,width=10,height=2)
self.text1.place(x=680,y=175)
self.text2 = ek.Text(self.mywindow, font=15,width=10,height=2)
self.text2.place(x=680,y=275)
self.text3 = ek.Text(self.mywindow, font=15, width=10, height=2)
self.text3.place(x=680, y=375)
self.mywindow.mainloop()
def show_picture(self):
# 1.选择文件
self.path = askopenfilename(title="选择文件")
# 2.处理文件
img = Image.open(fr'{self.path}')
img = img.resize((270,270),PIL.Image.ANTIALIAS)
# 生成一张图像
img_png = ImageTk.PhotoImage(img)
# 3,。设置图像
self.label_img.config(image=img_png)
self.label_img.image=img_png
self.cv_img.create_image(5,5,anchor="nw",image=img_png) # 船锚
# 通过类新建一个对象
xi_tong = da_fen()
xi_tong.start()
qiyuan -ding talk
最新推荐文章于 2024-08-21 11:30:00 发布