Image resize under PhotoImage

后端 未结 4 797
盖世英雄少女心
盖世英雄少女心 2020-11-29 08:07

I need to resize an image, but I want to avoid PIL, since I cannot make it work under OS X - don\'t ask me why...

Anyway since I am satisfied with gif/pgm/ppm, the P

4条回答
  •  庸人自扰
    2020-11-29 09:04

    If you don't have PIL installed --> install it

    (for Python3+ users --> use 'pip install pillow' in cmd)

    from tkinter import *
    import tkinter
    import tkinter.messagebox
    from PIL import Image
    from PIL import ImageTk
    
    master = Tk()
     
    def callback():
        print("click!")
    
    width = 50
    height = 50
    img = Image.open("dir.png")
    img = img.resize((width,height), Image.ANTIALIAS)
    photoImg =  ImageTk.PhotoImage(img)
    b = Button(master,image=photoImg, command=callback, width=50)
    b.pack()
    mainloop()
    

提交回复
热议问题