python - how can you display an image on a gui using tk in python2.7 -
i need away able show image when run python code in gui form if possible. have type in folder name , file name in code if know answer tried pil did save image folder want on gui
the code tk if necessary
from tkinter import * root = tk() toolbar = frame(root) # buttons in 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) # labels in 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()
hello if looking show image inside tk canvas needs ppm/pgm or gif: discussion python.org
however if looking load ppm, pgm or gif:
import tkinter tk root = tk.tk() root.title("display 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 frame, loads image using tk.photoimage, makes canvas , puts image onto canvas.
Comments
Post a Comment