Apr-06-2019, 08:01 PM
(Apr-06-2019, 04:33 AM)wuf Wrote: Hi jpezzThis command moves the A over from x=500 to x=600
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 :-)
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()