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?
#11
(Apr-06-2019, 04:33 AM)wuf Wrote: Hi jpezz

Make following alteration:
image2 = Image.open("pngs/b.png")
root.test_image2 = ImageTk.PhotoImage(image2)
image_label.place(x=600, y=50)
image_label.config(image=root.test_image2)
wuf :-)
This command moves the A over from x=500 to x=600
image_label.place(x=600, y=50)
Then this command overwrites the A with the B
image_label.config(image=root.test_image2)
The result is the B on top of the A with the B in the correct position.

Full program:
# -*- 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
import time

MAIN_WIN_TITLE = "Image Placements"
MAIN_WIN_XPOS = 200
MAIN_WIN_YPOS = 100
MAIN_WIN_WIDTH = 800
MAIN_WIN_HEIGHT = 600


root = tk.Tk()
#root.title(MAIN_WIN_TITLE)

# Remove titlebar
#root.overrideredirect(1)

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

# Get the .jpg image and convert it to tkinter format
image = Image.open("pngs/a.png")
root.test_image = ImageTk.PhotoImage(image)

#
# Create a label widget containig the image and place it directly on
# the main window
image_label = tk.Label(root, text="Image Label placed\non main window",
    compound='bottom', image=root.test_image)
image_label.place(x=500, y=50)
 
image2 = Image.open("pngs/b.png")
root.test_image2 = ImageTk.PhotoImage(image2)
image_label.place(x=600, y=50)
image_label.config(image=root.test_image2)

root.mainloop()
Reply


Messages In This Thread
RE: Why is it so difficult to just ouput an image where I want? - by jpezz - Apr-06-2019, 08:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Switching from tkinter to gtk is difficult! snakes 1 1,491 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