RobScott
Posts: 3
Joined: Sat Feb 20, 2016 6:30 pm

tkinter unable to display image

Wed May 18, 2016 8:00 am

Hello there.

I've been following an online tkinter tutorial, as it suits a lot of my needs. A modification I'm trying to introduce is for displaying an image. I'm struggling and wonder if any one could advise. Here's a section of the code, with my lines for the image file currently #'d out to make them obvious. Interestingly, although the image doesn't show, there are no errors when I run the program. I'm hoping the issue will be obvious and its just my novice status.

Thanks for your time.

Code: Select all

class StartPage (ttk.Frame):

    

    def __init__(self,parent,controller):

        ttk.Frame.__init__(self,parent)

        label = ttk.Label(self,text="Start Page", font=LARGE_FONT,)
        label.grid(row=0,column=0)

        image = ImageTk.PhotoImage(file='B:\BCP\C4_MAN_ENG_TEAM\Rob\Python\Visual\918.jpg')
        picture=ttk.Label(self,image=image)
        picture.grid(row=0, column=1)  
        
           
        button1 = ttk.Button(self, text="Visit Page 1",

                            command=lambda:controller.show_frame(PageOne))

        button1.grid(row=1,column=0)



        button2 = ttk.Button(self, text="Visit Page Two",

                            command=lambda:controller.show_frame(PageTwo))

        button2.grid(row=2, column=0)

User avatar
KnightOfPi
Posts: 50
Joined: Sun Dec 28, 2014 12:57 pm
Location: Vienna - Austria
Contact: Website

Re: tkinter unable to display image

Thu May 19, 2016 10:07 am

Hi RobScott,

i don't really know about TKinter, but found Kivy great for building GUIs:
http://www.knight-of-pi.org/kivy-on-a-r ... interface/

Originally, Kivy was built for Android-Touch-Interfaces, but it was ported for the RPi and supports mouse/keyboard interfacing.
It's lightweight, fast, pretty and quite easy to use...
Check out www.knight-of-pi.org for many beginner-friendly tutorials!

RobScott
Posts: 3
Joined: Sat Feb 20, 2016 6:30 pm

Re: tkinter unable to display image

Sat May 21, 2016 8:28 am

Hello there KnightOfPi

Thanks for the reply and advice. I'm really interested in checking out Kivy. Your website looks really good by the way!

I've got a lot of my program committed to tkinter, so I think I'll be persevering especially as I do think it is something I should learn.. But Kivy is something I'll definitely be checking out, especially if it is easy to learn.

Return to “Python”