仅使用Tkinter调整pgm图像的大小

时间:2016-06-12 00:30:56

标签: python tkinter photoimage

我有一个我显示的图像,我想调整(放大,实际上)该图像。这是我的代码,使用其他SO问题,但我没有结果 - 我的图像仍然具有相同的大小。调整按钮大小也不会改变图像大小。

我已经尝试过这个问题的答案:Image resize under PhotoImage但他们不会工作。

from Tkinter import *

root = Tk()
root.withdraw()

def cleanUp():
    root.destroy()

def openWebsite():
     print 'Will try to implement opening the website here.'

window = Toplevel(root)
window.protocol('WM_DELETE_WINDOW', cleanUp)

photo = PhotoImage(file="Header.pgm")

photo.zoom(2)

button = Button(window, image=photo, command=openWebsite)
button.pack()

root.mainloop()

1 个答案:

答案 0 :(得分:2)

PhotoImage.zoom() 返回新图片,但不会修改原始图片。尝试重新绑定photo,如下所示:

photo = photo.zoom(2)

来自帮助:

zoom(self, x, y='') method of Tkinter.PhotoImage instance
    Return a new PhotoImage with the same image as this widget
    but zoom it with X and Y.