Python Forum
simple tkinter question function call not opening image
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple tkinter question function call not opening image
#3
i tried that and that isn't working either,i wasn't sure if it was the name of the image ,the path or what but i tried both as parameters when calling the function open_image(). but tkinter just opens the geometry window and the blank 200x200 Frame but no image.
i dont see what is going wrong here.
this is where i am grabbing the image: photo = ImageTk.PhotoImage(Image.open(image_name))
this is where i am creating the Label to pack the photo onto : photo_label = Label(image=photo)
then just pack the dang thing to the frame
and call the function with my image..

from tkinter import *
from PIL import ImageTk,Image


root = Tk()
root.geometry("400x400")


def open_image(image_name):
	frame = Frame(root,width=200,height=200,bd=5,bg='white')
	frame.pack(pady=15)


	photo = ImageTk.PhotoImage(Image.open(image_name))
	photo_label = Label(image=photo)
	photo_label.pack()

open_image('babu.jpg')  #the name of the image is babu.jpg 

root.mainloop()
Reply


Messages In This Thread
RE: simple tkinter question function call not opening image - by gr3yali3n - Aug-01-2022, 05:56 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Wont create Image from function the_muffin_man 10 2,258 Jul-10-2024, 06:20 PM
Last Post: AdamHensley
  Tkinter: An image and label are not appearing. emont 7 2,510 Mar-21-2024, 03:00 PM
Last Post: deanhystad
  Using Tkinter inside function not working Ensaimadeta 5 7,270 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  GUI Problem / call another function / fill QListwidget flash77 5 1,631 Jul-30-2023, 04:29 PM
Last Post: flash77
  Beginner question re: Tkinter geometry return2sender 3 1,659 Jun-19-2023, 06:19 PM
Last Post: deanhystad
  Tkinter GUI question texan1836 3 2,936 Apr-13-2023, 03:12 AM
Last Post: deanhystad
  My Background Image Is Not Appearing (Python Tkinter) HailyMary 2 8,538 Mar-14-2023, 06:13 PM
Last Post: deanhystad
  help needed running a simple function in pyqt5 diodes 27 11,643 Jan-24-2023, 12:19 PM
Last Post: GetOnData
  [Tkinter] Tkinter don't change the image DQT 2 2,580 Jul-22-2022, 10:26 AM
Last Post: menator01
  Tkinter won't run my simple function AthertonH 6 5,704 May-03-2022, 02:33 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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