Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Add Photo in Python
#1
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]
Reply
#2
(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
Reply
#3
(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]
Reply
#4
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()
Reply
#5
(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, :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  aoigram, pil Help with photo processing kolpac21 0 529 Aug-07-2023, 04:59 PM
Last Post: kolpac21
  [split] Python Pillow - Photo Manipulation keegan_010 1 2,942 Oct-11-2018, 09:57 AM
Last Post: Larz60+
  Python Pillow - Photo Manipulation keegan_010 2 2,871 Oct-11-2018, 03:49 AM
Last Post: keegan_010
  Closing an image opened by Pillow in Window Photo Viewer bigmit37 16 26,099 Aug-11-2017, 03:54 AM
Last Post: grahamnt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020