2016-06-12 67 views
0

我有一張圖片可以顯示,而且我想調整其大小(實際上是放大)。這是我的代碼,使用其他SO問題,但我沒有得到任何結果 - 我的圖像仍然具有相同的大小。調整按鈕大小也不會更改圖像大小。僅使用Tkinter調整pgm圖像的尺寸

我試過這個問題的答案: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() 

回答

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.