简体   繁体   中英

How do i auto-scale GIF images on Tkinter to best fit any resolution?

I am inserting GIF image onto my GUI using Tkinter. However I do not know how to auto-scale the size of the image to best fit any resolution. Below are my coding:

from tkinter import * 
import base64
import urllib.request

URL ="file:///C:/Users/Student/Desktop/ezgif.com-resize.gif"
link = urllib.request.urlopen(URL)  
raw_data = link.read()
link.close()
next = base64.encodestring(raw_data)
image = PhotoImage(data=next)
label = Label(image = image)
label.place(x=0,y=0)

Can anyone help me?

Well the link suggests doing something like:

next = base64.encodestring(raw_data)
image = PhotoImage(data=next)
#image = image.zoom(2, 2)      # make it bigger
#image = image.subsample(2, 2) # make it smaller
label = Label(image = image)
label.place(x=0,y=0)

But these two methods are limited to integer scales. If you want to scale more flexibly then you will probably have to use PIL.ImageTk

PS you can use pack() rather than place() to make the image fit nicely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM