Python Forum
8 image grid with automatical image resize by screen resolution
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
8 image grid with automatical image resize by screen resolution
#2
Alexander,
I have seen this done using the PIL module, it has a function to resize called thumbnail.
Instead of label they used a canvas object create_image. below is an function from a class I'm using to preview an icon image in my script hope it will point you in the right direction:
def change_icon(self, size=(40,40)): # size of the icon 40x40
        from PIL.ImageTk import PhotoImage, Image # 2 PIL objects
        self.can.delete('object')                 # removes exiting object from canvas
        pic_num= self.combo3.current()            # retrieves the index number drop down
        pic= self.photos[pic_num]                 # gets photo from list
        print(pic)
        img_dir= r'../PIL/images/'
        img_obj= Image.open(img_dir + pic)
        img_obj.thumbnail(size, Image.ANTIALIAS)
        self.parent.one= self.img = PhotoImage(img_obj) #to prevent garbage collect
        icon= self.can.create_image(100,40,image=self.img,
                                    anchor='center',
                                    tag='object')
        self.parent.update()                                 # self.parent is my Tk()
Reply


Messages In This Thread
RE: 8 image grid with automatical image resize by screen resolution - by joe_momma - Dec-03-2019, 05:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm trying to visualize neuron weights with PIL but getting a white image. pointdexter16 0 147 Apr-13-2024, 02:48 PM
Last Post: pointdexter16
  Tkinter: An image and label are not appearing. emont 7 678 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  image conversion Skaperen 7 1,570 Sep-20-2023, 07:29 PM
Last Post: Skaperen
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 4,379 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  [Tkinter] Load image and show in label ko_fal 8 3,089 Oct-25-2022, 09:20 AM
Last Post: ko_fal
  [Tkinter] Image in Frame in Tabbed Widget Columbo 4 2,165 Sep-28-2022, 08:04 PM
Last Post: deanhystad
  simple tkinter question function call not opening image gr3yali3n 5 3,470 Aug-02-2022, 09:13 PM
Last Post: woooee
  [Tkinter] Tkinter don't change the image DQT 2 1,640 Jul-22-2022, 10:26 AM
Last Post: menator01
  [PyQt] Cannot Display Image after Selecting Image bintangkecil 4 2,605 Jun-12-2022, 08:18 AM
Last Post: Axel_Erfurt
  [Tkinter] Not able to get image as background in a Toplevel window finndude 4 3,935 Jan-07-2022, 10:10 PM
Last Post: finndude

Forum Jump:

User Panel Messages

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