Python Forum
how to resize image in canvas tkinter
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to resize image in canvas tkinter
#1
i am trying to resize the image to fit the window as i adjust the size. i dont know where im going wrong please help


from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk

root = Tk()


canvas_1 = Canvas(root)
canvas_1.pack(expand = True, fill = BOTH)
photo_1 = ImageTk.PhotoImage(Image.open("apps.20660.14434946597921362.9f02a0b5-6441-476c-9378-148e87e39b74.png"))
canvas_1_img = canvas_1.create_image(0,0,image = photo_1)
                  
                             
def resize(event):
    photo_2 =Image.open("apps.20660.14434946597921362.9f02a0b5-6441-476c-9378-148e87e39b74.png").resize((event.width,event.height), Image.ANTIALIAS)
    photo_can_2 = ImageTk.PhotoImage(photo_2)
    canvas_1.itemconfig(canvas_1_img, image = photo_can_2)
    
canvas_1.bind("<Configure>",lambda event: resize(event))

root.mainloop()
buran write Feb-05-2021, 07:05 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
how to resize image in canvas tkinter - by samuelmv30 - Feb-05-2021, 06:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 405 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 3,975 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  tkinter.TclError: can't invoke "canvas" command cybertooth 8 5,777 Feb-23-2023, 06:58 PM
Last Post: deanhystad
  simple tkinter question function call not opening image gr3yali3n 5 3,303 Aug-02-2022, 09:13 PM
Last Post: woooee
  [Tkinter] Tkinter don't change the image DQT 2 1,559 Jul-22-2022, 10:26 AM
Last Post: menator01
  [Tkinter] canvas image problem DPaul 4 6,266 Nov-24-2021, 07:06 AM
Last Post: DPaul
  [PyQt] Can't get MDIarea to resize automatically with Main Window JayCee 4 3,396 Aug-02-2021, 08:47 PM
Last Post: JayCee
  How to redraw an existing image to a different image TkInter zazas321 6 5,750 Jul-08-2021, 07:44 PM
Last Post: deanhystad
  tkinter showing image in button rwahdan 3 5,523 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  [Tkinter] Clickable Rectangles Tkinter Canvas MrTim 4 8,669 May-11-2021, 10:01 PM
Last Post: MrTim

Forum Jump:

User Panel Messages

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