[Tutor] Displaying Pictures & Text

Patty patty at cruzio.com
Sat Nov 6 17:50:07 CET 2010


Thank you!  I was getting confused, I thought I wouldn't need Tkinter.  I thought Tkinter is yet another addon library besides PIL.  Am I right or wrong?  So I actually need both?  And this brings me back to my _other_  question which is that as individuals go about downloading these addon libraries and their doc, how do you organize this on your computer system?   I can imagine that in corporations there are guidelines for this, but I am wondering what you all do? You could end up with addon libraries, doc and Readmes all over your hard disk

Patty
  ----- Original Message ----- 
  From: Wayne Werner 
  To: Patty 
  Cc: tutor at python.org 
  Sent: Saturday, November 06, 2010 7:16 AM
  Subject: Re: [Tutor] Displaying Pictures & Text


  On Fri, Nov 5, 2010 at 11:53 PM, Patty <patty at cruzio.com> wrote:

    Hi Alan - 

    I tried using ImageTk from the PIL library to display jpegs (and hopefully any picture type)  instead of just gif as you suggested below.  I read online that these these types of programs should 
    be run from executables not in the interpreter but it crashes and I can't read the error.  Here is the program:

    import Image
    import ImageTk

    fhdl = Image.open("C:\Users\StarShip\PyProgs\SuitGirl.jpg")
    ImageTk.PhotoImage(fhdl)


  Before you convert to an ImageTk, you need to first create a toplevel window:


  import Image
  import ImageTk
  import Tkinter as tk


  root = tk.Tk()
  #put your code here


  And that should work. You'll still have to add the widgets and what-nots so you can present your image, but in order to create an image with ImageTk, you need to have a toplevel window created.


  That's what this is telling you


    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:\Python26\lib\site-packages\PIL\ImageTk.py", line 113, in __init__
        self.__photo = apply(Tkinter.PhotoImage, (), kw)
      File "C:\Python26\lib\lib-tk\Tkinter.py", line 3285, in __init__
        Image.__init__(self, 'photo', name, cnf, master, **kw)
      File "C:\Python26\lib\lib-tk\Tkinter.py", line 3226, in __init__
        raise RuntimeError, 'Too early to create image'
    RuntimeError: Too early to create image




  HTH,
  Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101106/cf5fed74/attachment-0001.html>


More information about the Tutor mailing list