Jpg in tkinter

Thread Solved

Join Date: Jun 2006
Posts: 187
Reputation: Matt Tacular is an unknown quantity at this point 
Solved Threads: 7
Matt Tacular's Avatar
Matt Tacular Matt Tacular is offline Offline
Unverified User

Jpg in tkinter

 
0
  #1
Jan 19th, 2007
I know wxpython is supposed to be better than tkinter, but I can't find any easy to understand tutorials on how to begin using wxpython. But anyway. How can I get tkinter to load up a jpg?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 608
Reputation: jrcagle is on a distinguished road 
Solved Threads: 150
jrcagle jrcagle is offline Offline
Practically a Master Poster

Re: Jpg in tkinter

 
0
  #2
Jan 19th, 2007
Originally Posted by Matt Tacular View Post
I know wxpython is supposed to be better than tkinter...
Not if your code needs to run on a Mac ...

But anyway. How can I get tkinter to load up a jpg?
The best bet is to get PIL, the Python Imaging Library. Link here.

Then you can construct some simple code like

  1. import Image, ImageTk
  2.  
  3. im = Image.open(filename) # loads a wide variety of file types as a
  4. # PIL image. The PIL image has a
  5. # rich set of methods
  6.  
  7. tkim = ImageTk.PhotoImage(im) # Converts to Tkinter-friendly
  8. # image type

From there, you can pass the tkim object as a parameter to anything that will accept an image: a Label(), a Button(), a Canvas() ...

Hope it helps,
Jeff
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC