Python Forum
[Tkinter] Why is it so difficult to just ouput an image where I want?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Why is it so difficult to just ouput an image where I want?
#14
Hi jpezz

Thanks for your reply. In a label you can insert one image only! But you can place many label each containing a image in a frame container.
Here a script with totally three image label in one row: (For the trial all with the same image!)
# -*- coding: utf-8 -*

try:
    # Import Tkinter for Python 2.xx
    import Tkinter as tk
except ImportError:
    # Or import Tkinter for Python 3.xx
    import tkinter as tk
    
from PIL import Image, ImageTk

MAIN_WIN_TITLE = "Image Placements"
MAIN_WIN_XPOS = 100
MAIN_WIN_YPOS = 100
MAIN_WIN_WIDTH = 800
MAIN_WIN_HEIGHT = 600
 
main_win = tk.Tk()
main_win.title(MAIN_WIN_TITLE)

# Placement of the main window
main_win.geometry("{}x{}+{}+{}".format(
    MAIN_WIN_WIDTH, MAIN_WIN_HEIGHT, MAIN_WIN_XPOS, MAIN_WIN_YPOS))

# Get the .jpg image and convert it from pil-format to tk-format
pil_image_a = Image.open("pngs/a.jpg")
main_win.tk_image_a = ImageTk.PhotoImage(pil_image_a)

image_container = tk.Frame(main_win)
image_container.pack()

# Place first image-label in the image-container
image_label = tk.Label(image_container, text="Image-1",
    compound='bottom', image=main_win.tk_image_a)
image_label.grid(row=0, column=0)

# Place second image-label to the left side of first label
# in the image-container
image_label = tk.Label(image_container, text="Image-2",
    compound='bottom', image=main_win.tk_image_a)
image_label.grid(row=0, column=1)

# Place third image-label to the left side of second label
# in the image-container
image_label = tk.Label(image_container, text="Image-3",
    compound='bottom', image=main_win.tk_image_a)
image_label.grid(row=0, column=2)


main_win.mainloop()
What is the size of your images?

wuf :-)
Reply


Messages In This Thread
RE: Why is it so difficult to just ouput an image where I want? - by wuf - Apr-07-2019, 03:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Switching from tkinter to gtk is difficult! snakes 1 1,506 Aug-08-2022, 10:35 PM
Last Post: woooee

Forum Jump:

User Panel Messages

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