python中imagetk中delete方法_使用ImageTk调整图像大小。使用Tkinter/Python调整图像大小...

你离得很近,但还不是很近。因此,我改变了你的例子,让它发挥作用:import Tkinter as tk

from PIL import Image, ImageTk

from itertools import cycle

class App(tk.Tk):

def __init__(self, image_files, x, y, delay):

tk.Tk.__init__(self)

self.geometry('+{}+{}'.format(x,y))

self.delay = delay

#self.pictures = cycle((ImageTk.PhotoImage(file=image), image) for image in image_files)

self.pictures = cycle(image for image in image_files)

self.pictures = self.pictures

self.picture_display = tk.Label(self)

self.picture_display.pack()

self.images = [] # to keep references to images.

def show_slides(self):

img_name = next(self.pictures)

image_pil = Image.open(img_name).resize((300, 300)) #

self.images.append(ImageTk.PhotoImage(image_pil))

self.picture_display.config(image=self.images[-1])

self.title(img_name)

self.after(self.delay, self.show_slides)

def run(self):

self.mainloop()

delay = 3500

image_files = [

'./empty.gif',

'./empty2.gif',

'./empty1.gif'

]

x = 200

y = 150

app = App(image_files,x,y,delay)

app.show_slides()

app.run()

基本上,在创建ImageTk.PhotoImage实例之前,必须使用PIL image完成图像大小调整。在两个关键点上,我在示例中做了评论,所以您知道应该在哪里查找。希望这有帮助。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值