0

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

我已经尝试了这个 SO 问题的答案:Image resize under PhotoImage but they won't work。

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()
4

1 回答 1

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.
于 2016-06-12T01:17:17.137 回答