Python Forum
Zooming a tkinter image
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Zooming a tkinter image
#1
I am trying to create a program that can display images, this is going to tie in with some bigger projects in the future so I thought of just making the photo displaying program now to save me having to rewrite all the code, right now I am using the program to display 32x32 sprites but it looks tiny in comparison with my monitor (which is bad) so I wanted a way to zoom them without having to go back into Photoshop to redraw the images.

import tkinter
from tkinter import *
import threading
from threading import Timer

window = Tk()
window.title("Test")
window.config(bg = "white")

Px = 0
Py = 0
zw = 8
zh = 8
PlayerF1 = PhotoImage(file = "F1.png")
PlayerF2 = PhotoImage(file = "F2.png")
PlayerF3 = PhotoImage(file = "F3.png")
PlayerF1.zoom(zw, zh)
PlayerF2.zoom(zw, zh)
PlayerF3.zoom(zw, zh)
Playerd = Label(window, image = PlayerF1, bg = "white")

Playerd.place(x = 30, y = 30)

def ani():
    print("Cycle")
    def Frame1():
        print("Loop")
        Playerd.config(image = PlayerF1)
        window.update()
        def Frame2():
            print("Loop2")
            Playerd.config(image = PlayerF2)
            window.update()
            def Frame3():
                print("Loop3")
                Playerd.config(image = PlayerF3)
                window.update()
                ani()
                
            t = Timer(0.1, Frame3)
            t.start()
        t = Timer(0.1, Frame2)
        t.start()
    t = Timer(0.1, Frame1)
    t.start()

ani()
window.mainloop()
As you can see, I tried to use .zoom(), but it hasn't actually done anything to the image.

Right now I am also using the program to test if animations would be viable with this kind of code, so, for the most part, you can ignore ani() and its nested defs.

Any help would be greatly appreciated!
Reply
#2
you may want to take a look at: https://stackoverflow.com/a/48137257
Reply
#3
(Nov-09-2019, 03:17 PM)Larz60+ Wrote: you may want to take a look at: https://stackoverflow.com/a/48137257

I have seen that post before, it didn't really help that much (at least for me)...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 396 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 3,972 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  simple tkinter question function call not opening image gr3yali3n 5 3,300 Aug-02-2022, 09:13 PM
Last Post: woooee
  [Tkinter] Tkinter don't change the image DQT 2 1,556 Jul-22-2022, 10:26 AM
Last Post: menator01
  How to redraw an existing image to a different image TkInter zazas321 6 5,744 Jul-08-2021, 07:44 PM
Last Post: deanhystad
  tkinter showing image in button rwahdan 3 5,516 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  tkinter button image Nick_tkinter 4 3,954 Mar-04-2021, 11:33 PM
Last Post: deanhystad
  how to resize image in canvas tkinter samuelmv30 2 17,547 Feb-06-2021, 03:35 PM
Last Post: joe_momma
  Latex image too big on tkinter using sympy 4096 1 2,886 Nov-05-2020, 08:05 AM
Last Post: DPaul
Photo Tkinter TEXT background image _ShevaKadu 5 7,649 Nov-02-2020, 10:34 AM
Last Post: joe_momma

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020