0

i need away to be able to show an image when i run the python code in its gui form if possible. Also do i have to type in the folder name and file name in the code if you know the answer i tried pil all it did was save the image into a folder i want this on the gui

the code for the tk if it is necessary

from Tkinter import *

root = Tk()

toolbar = Frame(root)

# All the buttons in my program
b = Button(toolbar, text="Home", width=9)
b.pack(side=LEFT, padx=2, pady=2)

b = Button(toolbar, text="About-us", width=9)
b.pack(side=LEFT, padx=2, pady=2)

b = Button(toolbar, text="Contact-us", width=9)
b.pack(side=LEFT, padx=2, pady=2)

b = Button(toolbar, text="Travelling", width=9)
b.pack(side=LEFT, padx=2, pady=2)


toolbar.pack(side=TOP, fill=X)

# All the labels in my program
o = Label(root,text="Frank Anne",font =("Italic",18,"bold"))
o.pack()

toolbar1 = Frame(root)

o=Label(root,)
o.pack()


o=Label(root,text ="Age:                     27")
o.pack()

o=Label(root,text ="Address:                 71 strawberry lane, JU8 8TY")
o.pack()

toolbar1.pack(side=BOTTOM, fill=X)









mainloop()

2 Answers 2

1

Hello if your looking to show an image inside a tk Canvas it needs to be a PPM/PGM or GIF: discussion from python.org

However if your looking to load a PPM, PGM or GIF:

import Tkinter as tk
root = tk.Tk()
root.title("display a website image")
photo = tk.PhotoImage(file= r"C:\Some\Local\location\smile.gif")
cv = tk.Canvas()
cv.pack(side='top', fill='both', expand='yes')
cv.create_image(10, 10, image=photo, anchor='nw')
root.mainloop()

This creates a frame, loads the image using tk.PhotoImage, then makes a canvas and puts the image onto the canvas.

Sign up to request clarification or add additional context in comments.

Comments

1

If I understand, you just want to show an image using Tkinter?

To do this, you can use a Canvas widget filled with your image.

Here is an example:

can = Canvas(window, width=160, height=160, bg='white')
pic = PhotoImage(file='picture.jpg')
item = can.create_image(80, 80, image=pic)

3 Comments

You don't need to use a canvas; you can also use a label widget.
I thought that was the "cleanest" way to make it.
My point was, saying somebody needs to do something a certain way implies it is the only way, but in this case it's not the only way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.