944,161 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 4602
  • Python RSS
Jan 19th, 2007
0

Jpg in tkinter

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 7
Unverified User
Matt Tacular is offline Offline
187 posts
since Jun 2006
Jan 19th, 2007
0

Re: Jpg in tkinter

I know wxpython is supposed to be better than tkinter...
Not if your code needs to run on a Mac ...

Quote ...
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

Python Syntax (Toggle Plain Text)
  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
Reputation Points: 92
Solved Threads: 156
Practically a Master Poster
jrcagle is offline Offline
608 posts
since Jul 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Using a Variable to Identify an Instance
Next Thread in Python Forum Timeline: A line class for coordinate geometry





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC