Python Forum
Add Photo in Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Add Photo in Python (/thread-14336.html)



Add Photo in Python - adninqasifa - Nov-25-2018

Helloo,

Helloo, I have some question, i try to run simple Program for add photos in IDLE Python but not working. It is because to large or something? Can you tell me how and why? Thank you.

This is my Code:
from tkinter import *

root = Tk()

photo = PhotoImage(file="mu_logo.png")     #Nama file foto
label = Label(root, image=photo)
label.pack()

root.mainloop()
[Image: Screenshot%2B%25289%2529.png]


RE: Add Photo in Python - snippsat - Nov-25-2018

(Nov-25-2018, 12:09 PM)adninqasifa Wrote: i try to run simple Program for add photos in IDLE Python but not working.
It's not IDLE but Atom you use.
The code is okay and work fine for me.
Try running from command line and see if work then and if Atom setup can be a problem.

I would advise using VS Code,it's more geared against Python.
VS Code from start


RE: Add Photo in Python - adninqasifa - Nov-25-2018

(Nov-25-2018, 12:56 PM)snippsat Wrote:
(Nov-25-2018, 12:09 PM)adninqasifa Wrote: i try to run simple Program for add photos in IDLE Python but not working.
It's not IDLE but Atom you use.
The code is okay and work fine for me.
Try running from command line and see if work then and if Atom setup can be a problem.

I would advise using VS Code,it's more geared against Python.
VS Code from start

Oops, sorry wrong image, this is my IDLE Python image (not working). I try in cmd too, and it is not working too.
[Image: Screenshot%2B%252810%2529.png]


RE: Add Photo in Python - snippsat - Nov-25-2018

To make it more flexible so it support .png and .jpg,not all version on Tkinter dos this.
pip install pillow
Also do not use *,even if many dos use this in GUI programming.
import tkinter as tk
from PIL import ImageTk, Image

root = tk.Tk()
#photo = PhotoImage(file="blue.jpg")     #Nama file foto
photo = ImageTk.PhotoImage(Image.open("mu_logo.png"))
label = tk.Label(root, image=photo)
label.pack()
root.mainloop()



RE: Add Photo in Python - adninqasifa - Nov-26-2018

(Nov-25-2018, 02:36 PM)snippsat Wrote: To make it more flexible so it support .png and .jpg,not all version on Tkinter dos this.
pip install pillow
Also do not use *,even if many dos use this in GUI programming.
import tkinter as tk
from PIL import ImageTk, Image

root = tk.Tk()
#photo = PhotoImage(file="blue.jpg")     #Nama file foto
photo = ImageTk.PhotoImage(Image.open("mu_logo.png"))
label = tk.Label(root, image=photo)
label.pack()
root.mainloop()

Thank you, this is the best Answer, :)