Reputation: 139
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()
Upvotes: 0
Views: 18450
Reputation: 1404
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)
Upvotes: 1
Reputation: 7906
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.
Upvotes: 1