【问题标题】:Resize pgm image using Tkinter only [duplicate]仅使用 Tkinter 调整 pgm 图像的大小 [重复]
【发布时间】:2016-06-12 00:30:56
【问题描述】:

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

我已经尝试了这个 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()

【问题讨论】:

    标签: python tkinter photoimage


    【解决方案1】:

    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 2012-04-19
      • 2015-04-12
      • 1970-01-01
      • 2014-02-01
      • 2021-04-21
      相关资源
      最近更新 更多