python tk展示图片

python 复制代码
from tkinter import *
from PIL import ImageTk, Image

root = Tk()
root.title("展示图片")

# 打开图片
image = Image.open("DSC_2040.jpg")
# 调整图片大小
image = image.resize((300, 300), Image.ANTIALIAS)
# 创建图像对象
img = ImageTk.PhotoImage(image)

# 创建标签并展示图片
label = Label(root, image=img)
label.pack()

root.mainloop()
相关推荐
小徐敲java3 分钟前
python的FastAPI框架
开发语言·python·fastapi
CHANG_THE_WORLD18 分钟前
Python 切片操作全面解析
开发语言·python
是一个Bug35 分钟前
Spring事件监听器在电商订单系统中的应用
java·python·spring
shangjian0071 小时前
Python基础-闭包和装饰器
开发语言·python
三维空间1 小时前
如何在Python多进程中避免死锁问题?
python
冤大头编程之路1 小时前
Python并发编程实操教程:多线程/多进程/异步全解析
python
dhdjjsjs1 小时前
Day30 Python Study
开发语言·前端·python
Eric.Lee20211 小时前
mujoco构建无物理约束的几何体运动
python·物理引擎·mujoco·物理模型仿真
wadesir2 小时前
用Python实现ggplot2风格绘图(零基础入门Seaborn与Matplotlib美化技巧)
开发语言·python·matplotlib
ㄣ知冷煖★2 小时前
基于openEuler操作系统的图神经网络应用开发:以Cora数据集节点分类为例的研究与实践
python