#Making Image Viewer In Tkinter
from tkinter import *
from PIL import ImageTk, Image
root = Tk()
root.title('Image Viewer @_python.py_')
root.resizable(False, False)
root.iconbitmap('photo.ico')
#add image
my_img1 = ImageTk.PhotoImage(Image.open('img/1.1.jpg'))
my_img2 = ImageTk.PhotoImage(Image.open('img/1.2.jpg'))
my_img3 = ImageTk.PhotoImage(Image.open('img/1.3.jpg'))
my_img4 = ImageTk.PhotoImage(Image.open('img/1.jpg'))
my_img5 = ImageTk.PhotoImage(Image.open('img/2.jpg'))
my_img6 = ImageTk.PhotoImage(Image.open('img/3.jpg'))
my_img7 = ImageTk.PhotoImage(Image.open('img/4.jpg'))
my_img8 = ImageTk.PhotoImage(Image.open('img/5.jpg'))
my_img9 = ImageTk.PhotoImage(Image.open('img/6.jpg'))
my_img10 = ImageTk.PhotoImage(Image.open('img/7.jpg'))
#add all image in list
image_list = [my_img1, my_img3, my_img2, my_img4, my_img5, my_img6, my_img7, my_img8, my_img9, my_img10]
#making lapel for image
my_label = Label(image=my_img1)
my_label.grid(row=0, column=0, columnspan=3)
# action on button for back , exit, forward
def forward(image_number):
global my_label
global button_forward
global button_back
my_label.grid_forget()
my_label = Label(image= image_list[image_number-1])
button_forward = Button(root, text=" >> ", command= lambda:forward(image_number+1), font='Helvetica 15 bold')
button_back = Button(root, text=" << ", command= lambda : back(image_number-1), font='Helvetica 15 bold')
if image_number == 10:
button_forward = Button(root, text=" >> ", state=DISABLED, font='Helvetica 15 bold')
button_forward.grid(row=1, column=2)
button_back.grid(row=1, column=0)
my_label.grid(row=0, column=0, columnspan=3)
# Update Status bar
status=Label(root, text='Image '+ str(image_number) +' of '+str(len(image_list)), bd=1, relief=SUNKEN, anchor=E)
status.grid(row=2, column=0, columnspan=3, sticky=W+E)
def back(image_number):
global my_label
global button_forward
global button_back
my_label.grid_forget()
my_label=Label(image=image_list[image_number-1])
button_forward=Button(root, text=" >> ", command=lambda:forward(image_number+1) ,font='Helvetica 15 bold')
button_back=Button(root, text=" << ", command=lambda:back(image_number-1), font='Helvetica 15 bold')
if image_number == 1:
button_back=Button(root, text=" << ", state=DISABLED)
button_forward.grid(row=1, column=2)
button_back.grid(row=1, column=0)
my_label.grid(row=0, column=0, columnspan=3)
# Update Status bar
status=Label(root, text='Image '+ str(image_number) +' of '+str(len(image_list)), bd=1, relief=SUNKEN, anchor=E)
status.grid(row=2, column=0, columnspan=3, sticky=W+E)
#set button on the root screen
button_back = Button(root, text=" << ", command=back, state=DISABLED , font='Helvetica 15 bold').grid(row=1, column=0)
button_exit = Button(root, text=" EXIT ", command= exit , font='Helvetica 15 bold').grid(row=1, column=1, pady=10)
button_forward = Button(root, text=" >> ", font='Helvetica 15 bold', command=lambda: forward(2)).grid(row=1, column=2)
root.mainloop()
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Pillow是Python中一个常用的图像处理库,可以进行图像的读取、处理、保存等操作。使用Pillow,你可以很容易地实现一个图片切换查看器程序,让用户可以浏览并切换不同的图片。这个图片切换查看器程序的实现思路如下:1. **导入Pillow库**:首先,确保你已经安装了Pillow库,并导入它。2. **创建Tkinter主窗口**:使用Tkinter创建一个主窗口,作为图像查看器的界面。3. **加载图片**:使用Pillow库加载需要显示的图片,并将其显示在Tkinter主窗口中的标签或画布中。4. **添加切换功能**:为了让用户能够切换图片,可以在界面上添加按钮或者键盘事件,当用户点击按钮或按下键盘时,切换到下一张或上一张图片。5. **优化显示**:可以考虑添加缩放、旋转等功能,使用户能够更灵活地查看图片。6. **添加其他功能**:根据需要,可以添加其他功能,如保存图片、调整图片亮度和对比度等。这个程序可以提供一个简单而有效的方式来查看图片,特别适用于需要频繁查看大量图片的情况,比如浏览照片集或者参考图像资料。通过使用Pillow库,你可以很轻松地实现图片切换查看程序。
资源推荐
资源详情
资源评论
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![7z](https://img-home.csdnimg.cn/images/20210720083312.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
收起资源包目录
![package](https://csdnimg.cn/release/downloadcmsfe/public/img/package.f3fc750b.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/PNG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
![folder](https://csdnimg.cn/release/downloadcmsfe/public/img/folder.005fa2e5.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/JPG.png)
![file-type](https://csdnimg.cn/release/download/static_files/pc/images/minetype/UNKNOWN.png)
共 13 条
- 1
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/38f8d9bd3f8a4a9cb31200141d837fcb_jackchuanqi.jpg!1)
传奇开心果编程
- 粉丝: 9593
- 资源: 397
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
最新资源
- AI绘画工具介绍(文档)
- pandas-2.2.2-cp311-cp311-musllinux-1-1-aarch64.whl
- 小程序开发基础与简单示例.pdf
- matlab:读取图像+显示图像+显示图像的直方图+直方图均衡
- pandas-2.2.2-cp311-cp311-manylinux-2-17-x86-64.manylinux2014.whl
- 如何充分运用ansys的HELP
- pandas-2.2.2-cp311-cp311-musllinux-1-1-x86-64.whl
- C语言可变长数组(VLA)详解与应用
- android-studio-2024.1.1.12-windows-zip.zip.001
- 辰光PHP客服系统多商户全开源V3.1版+安装教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback](https://img-home.csdnimg.cn/images/20220527035711.png)
![feedback-tip](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)