Python Forum

Full Version: Add Photo in Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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]
(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
(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]
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()
(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, :)