Bottom Page

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!
Quote
#2
you may want to take a look at: https://stackoverflow.com/a/48137257
Quote
#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)...
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Image editor using Tkinter and PIL Raulica 2 277 Dec-03-2019, 10:10 PM
Last Post: joe_momma
  Unable to put background image on Tkinter Frame jenkins43 2 815 Nov-27-2019, 11:38 AM
Last Post: jenkins43
  Can't load a png image tkinter Pythenx 2 1,865 May-04-2019, 05:43 PM
Last Post: woooee
  how to insert image into Text widget Tkinter atlass218 5 2,541 Apr-17-2019, 05:28 AM
Last Post: atlass218
  How to in PySide/PyQt, zooming in and out UI Vladlen 0 498 Feb-13-2019, 02:11 PM
Last Post: Vladlen
  Display image in tkinter dan789 9 12,719 Dec-09-2018, 08:17 PM
Last Post: dan789
  Tkinter Image Display Weird Tearing Upon Transforming Emerest 6 1,740 Sep-01-2018, 11:46 PM
Last Post: Emerest

Forum Jump:


Users browsing this thread: 1 Guest(s)