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
#1
Hello everybody,
i am very new in python and have a problem.
I use Python 3 on a Raspberry.
I wanted to have a little program what have an full width grid with 2 rows and 4 columns. The images inside every column i want to change by Gpio later. But i stuck at the grid with the images.
I wanted to show in every field an image. This works. I decided to show images inside label (i am not sure if this is correct way).
Now i have the problem that my window is full size. Depends on screen resolution. All my Images are 800 x 800. So i want to scale them down that i have in first row 4 images and in second row 4 images.
For example when i have 1024 screen width every image must be not more then 256px.
But exactly for this i dont find solution. I read a lot and tried several ways. But no success.
In the moment the images strech all and my grid is broken.

This is my actuall code:
# import tkinter module
from tkinter import *
from tkinter.ttk import *

# creating main tkinter window/toplevel
master = Tk()
# Turn of window frame
master.overrideredirect(1)
# getting screen's width & height in pixels
screen_width = master.winfo_screenwidth()
screen_height = master.winfo_screenheight()
# New Var with Geometry size
screen_resolution = str(screen_width)+'x'+str(screen_height)
# Set size for Window
master.geometry(screen_resolution)

# Grid settings
grid.rowconfigure(master, 0, weight=1)
grid.columnconfigure(master, 0, weight=1)

# Load images
# Row 1 Standard 
imgr1 = PhotoImage(file=r"images\close1.png")
imgr1s = imgr1.subsample(1, 1)
imgr1_1 = PhotoImage(file=r"images\close2.png")
imgr1_1s = imgr1_1.subsample(1, 1)
imgr1_2 = PhotoImage(file=r"images\close3.png")
imgr1_2s = imgr1_2.subsample(1, 1)
imgr1_3 = PhotoImage(file=r"images\close4.png")
imgr1_3s = imgr1_3.subsample(1, 1)

# Row 2 Standard 
imgr2 = PhotoImage(file=r"images\close5.png")
imgr2s = imgr2.subsample(2, 2)
imgr2_1 = PhotoImage(file=r"images\close6.png")
imgr2_1s = imgr2_1.subsample(2, 2)
imgr2_2 = PhotoImage(file=r"images\close7.png")
imgr2_2s = imgr2_2.subsample(2, 2)
imgr2_3 = PhotoImage(file=r"images\close8.png")
imgr2_3s = imgr2_3.subsample(2, 2)


# Row 1
# Set images in Row 1 by Label
Label(master, image=imgr1s).grid(row=0, column=0, pady=1, sticky=N+S+E+W)
Label(master, image=imgr1_1s).grid(row=0, column=1, pady=1, sticky=N+S+E+W)
Label(master, image=imgr1_2s).grid(row=0, column=2, pady=1, sticky=N+S+E+W)
Label(master, image=imgr1_3s).grid(row=0, column=3, pady=1, sticky=N+S+E+W)

# Row 2
# Set images in Row 2 by Label
Label(master, image=imgr2).grid(row=1, column=0, pady=1, sticky=N+S+E+W)
Label(master, image=imgr2_1).grid(row=1, column=1, pady=1, sticky=N+S+E+W)
Label(master, image=imgr2_2).grid(row=1, column=2, pady=1, sticky=N+S+E+W)
Label(master, image=imgr2_3).grid(row=1, column=3, pady=1, sticky=N+S+E+W)

# infinite loop which can be terminated  
# by keyboard or mouse interrupt 
mainloop() 
Hopefully somebody can bring me to right way.
Thx for help
Alexander
Reply


Messages In This Thread
8 image grid with automatical image resize by screen resolution - by AlexanderO - Nov-23-2019, 11:16 AM

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 132 Apr-13-2024, 02:48 PM
Last Post: pointdexter16
  Tkinter: An image and label are not appearing. emont 7 646 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  image conversion Skaperen 7 1,558 Sep-20-2023, 07:29 PM
Last Post: Skaperen
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 4,333 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  [Tkinter] Load image and show in label ko_fal 8 3,069 Oct-25-2022, 09:20 AM
Last Post: ko_fal
  [Tkinter] Image in Frame in Tabbed Widget Columbo 4 2,161 Sep-28-2022, 08:04 PM
Last Post: deanhystad
  simple tkinter question function call not opening image gr3yali3n 5 3,455 Aug-02-2022, 09:13 PM
Last Post: woooee
  [Tkinter] Tkinter don't change the image DQT 2 1,632 Jul-22-2022, 10:26 AM
Last Post: menator01
  [PyQt] Cannot Display Image after Selecting Image bintangkecil 4 2,596 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,927 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