Python Forum
[Tkinter] Tkinter don't change the image
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter don't change the image
Hello everyone.
I am using Python 2.7(if it nescessary).

Here is my code
from Tkinter import *
from PIL import Image, ImageTk
from os.path import exists
from pathlib import Path



file_dir = "bk.png";

def img_reset():

	#Load img
def move():
	global lab;

The code don't change lab 's image to "a.png", it still "bk.png"(line 19)
Thank you for helped me. Smile

  1. Python 2.7 reached end of life January 1, 2000 see:
  2. in python 3, you must change from Tkinter import *
    To: from tkinter import * (change case of tkinter)
    better to import specific modules, but won't cause an issue.
  3. (line 3) is never used
  4. pathlib is not supported by python 2.7, requires 3.6 or newer
  5. img1 (line 13) is never used

I'd suggest looking at a sample and retrying (random example:
As Larz60+ recommended upgrade to python3. After the recommended link, here is a snippet to work with.

import tkinter as tk
from tkinter import PhotoImage

def change_img(parent, label, images):
    if label['image'] == str(images[0]):
        label['image'] = str(images[1])
        label['image'] = 'pyimage1'
    parent.after(3000, lambda: change_img(parent, label, images))

root = tk.Tk()
img1 = PhotoImage(file='path/to/image1')
img2 = PhotoImage(file='path/to/image2')
label = tk.Label(root)
label['image'] = img1
img1.image = img1
img2.image = img2
root.after(3000, lambda:change_img(root, label, (img1, img2)))
BashBedlam likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter: An image and label are not appearing. emont 7 557 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 4,214 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  simple tkinter question function call not opening image gr3yali3n 5 3,411 Aug-02-2022, 09:13 PM
Last Post: woooee
  Tkinter - How can I change the default Notebook border color? TurboC 5 14,729 May-23-2022, 03:44 PM
Last Post: bigmac
  Can't get tkinter button to change color based on changes in data dford 4 3,410 Feb-13-2022, 01:57 PM
Last Post: dford
  tkinter change the text of the checkbox zazas321 1 3,817 Sep-17-2021, 06:19 AM
Last Post: zazas321
  How to redraw an existing image to a different image TkInter zazas321 6 5,852 Jul-08-2021, 07:44 PM
Last Post: deanhystad
  tkinter showing image in button rwahdan 3 5,596 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  tkinter button image Nick_tkinter 4 4,020 Mar-04-2021, 11:33 PM
Last Post: deanhystad
  how to resize image in canvas tkinter samuelmv30 2 17,704 Feb-06-2021, 03:35 PM
Last Post: joe_momma

Forum Jump:

User Panel Messages

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