Python Forum
[Tkinter] Image with pillow on macos not showing
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Image with pillow on macos not showing
#1
Hi there,

I'm fairly new to programming in Python and was going through a tutorial which came across GUI programming with tkinter (Python3).

I was entering the code, pressed the button which should, as per the tutorial, show the image on the canvas, but it failed. the image (size) was drawn and removed quickly, I only saw a slight black square being drawn before everything was white again.

As this is no new issue, I found I had to keep a reference to the image for garbage collection not to get rid of it, but that wasn't helping. So I came across this code as shown below as a very simple example showing an image.

To change platform (I'm on MacOS), I installed Python and pillow on a Windows VM of mine and the very same code ran without any problems. So I figured it's got something to do with MacOS and these versions of code.

I'm running:
* MacOS Mojave 10.14.4
* Python 3.7.3
* Pillow 6.0.0

Is this quite the same issue? or is there some difference in platforms how to get the image to show? Any pointers to the solution would be greatly appreciated, thanks in advance.

#!/usr/local/bin/python3
import tkinter
from PIL import Image, ImageTk
img = Image.open('images/img.jpg')
root = tkinter.Tk()
canvas = tkinter.Canvas(root, width=img.width, height=img.height,
    background='blue', borderwidth=0, )
canvas.pack()
tkimg = ImageTk.PhotoImage(img)
imagesprite = canvas.create_image(0, 0, anchor=tkinter.NW, image=tkimg)
root.mainloop()
Result on MacOS:
[Image: tk.png]

Result on Windows:
[Image: tk2.png]
Reply


Messages In This Thread
Image with pillow on macos not showing - by rhoekstra - May-04-2019, 08:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  macOS Sonoma (14) seems to need a newer version of Tcl/Tk gernophil 1 1,155 Oct-11-2023, 05:53 PM
Last Post: deanhystad
  UI modules: which is most suitable for macOS app design? Anon_Brown 1 1,908 Nov-19-2021, 06:24 PM
Last Post: Larz60+
  [Tkinter] image in label not showing? rwahdan 2 8,327 Jun-25-2021, 10:27 AM
Last Post: rwahdan
  tkinter showing image in button rwahdan 3 5,707 Jun-16-2021, 06:08 AM
Last Post: Yoriz
  macOS GUI pythonnewbi 5 3,096 Jul-05-2020, 03:56 PM
Last Post: ndc85430
  Pillow juuls04 4 3,347 Dec-30-2019, 04:55 AM
Last Post: joe_momma
  [Tkinter] macOS Catalina and Python menu issue SouthernYankee 7 6,913 Dec-11-2019, 02:02 AM
Last Post: chrstphrchvz
  Packaging VTK and ITK for macOS sandrider 0 2,040 Nov-01-2018, 05:24 AM
Last Post: sandrider
  About Dialog in PyQt5 on macOS cpuin 0 2,903 Jan-23-2018, 08:50 PM
Last Post: cpuin
  packaging a PyQt app for macOS danboid 0 3,145 Mar-30-2017, 06:57 PM
Last Post: danboid

Forum Jump:

User Panel Messages

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