Chargement d'une image

Résolu
panthere007 Messages postés 20 Date d'inscription vendredi 18 avril 2008 Statut Membre Dernière intervention 7 août 2009 - 1 sept. 2008 à 18:39
panthere007 Messages postés 20 Date d'inscription vendredi 18 avril 2008 Statut Membre Dernière intervention 7 août 2009 - 6 sept. 2008 à 18:04
Hello

hello

je voudrai mettre une image de fond dans une fenêtre (caneva ?) pour ensuite placer mes control par dessus
j'ai pas mal chercher mai on dirait que c est un problème de module.

#!/usr/bin/env python
# -*- coding:Utf-8 -*-
from Tkinter import *
from PIL import Image,ImageTk

image = Image.open("/home/taz/Desktop/python/1.png")
fond = ImageTk.PhotoImage(image)
#self.can.create_image(264,204,image=self.fond)

erreur:

Traceback (most recent call last):
  File "/home/taz/Desktop/python/comp_kernel_tk.py", line 7, in <module>
    fond = ImageTk.PhotoImage(image)
  File "/usr/lib/python2.5/site-packages/PIL/ImageTk.py", line 113, in __init__
    self.__photo = apply(Tkinter.PhotoImage, (), kw)
  File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 3282, in __init__
    Image.__init__(self, 'photo', name, cnf, master, **kw)
  File "/usr/lib/python2.5/lib-tk/Tkinter.py", line 3223, in __init__
    raise RuntimeError, 'Too early to create image'
RuntimeError: Too early to create image
Exception exceptions.AttributeError: "PhotoImage instance has no attribute '_PhotoImage__photo'" in ignored

Merci d'avance

Je suis sous linux debian sid:
voila ce qui est installer:

ii  python                                               2.5.2-2                                       An interactive high-level object-oriented language (default version)
ii  python-cairo                                         1.4.12-1.1                                    Python bindings for the Cairo vector graphics library
ii  python-central                                       0.6.8                                         register and build utility for Python packages
ii  python-ctypes                                        1.0.2-5                                       Python package to create and manipulate C data types
ii  python-dbg                                           2.5.2-2                                       Debug Build of the Python Interpreter (version 2.5)
ii  python-dbus                                          0.83.0-1                                      simple interprocess messaging system (Python interface)
ii  python-dev                                           2.5.2-2                                       Header files and a static library for Python (default)
ii  python-egenix-mxdatetime                             3.1.0-1                                       date and time handling routines for Python
ii  python-egenix-mxtools                                3.1.0-1                                       collection of additional builtins for Python
ii  python-elementtree                                   1.2.6-12                                      Light-weight toolkit for XML processing
ii  python-glade2                                        2.12.1-6                                      GTK+ bindings: Glade support
ii  python-gobject                                       2.14.2-1                                      Python bindings for the GObject library
ii  python-gtk2                                          2.12.1-6                                      Python bindings for the GTK+ widget set
ii  python-imaging                                       1.1.6-3                                       Python Imaging Library
ii  python-imaging-doc                                   1.1.6-3                                       Examples for the Python Imaging Library
ii  python-imaging-tk                                    1.1.6-3                                       Python Imaging Library - ImageTk Module
ii  python-logilab-astng                                 0.17.2-2.1                                    extend Python's abstract syntax tree
ii  python-logilab-common                                0.30.0-2                                      useful miscellaneous modules used by Logilab projects
ii  python-minimal                                       2.5.2-2                                       A minimal subset of the Python language (default version)
ii  python-newt                                          0.52.2-11.3                                   A NEWT module for Python
ii  python-numeric                                       24.2-9                                        Numerical (matrix-oriented) Mathematics for Python
ii  python-osd                                           0.2.14-3                                      Python bindings for X On-Screen Display library
ii  python-processing                                    0.52-1                                        library for running multiple Python processes using the threading AP
ii  python-pygame                                        1.7.1release-4.2                              SDL bindings for games development in Python
ii  python-qscintilla2                                   2.2-4                                         Python bindings for QScintilla 2
ii  python-qt3                                           3.17.4-1                                      Qt3 bindings for Python
ii  python-qt4                                           4.4.2-4                                       Python bindings for Qt4
ii  python-qt4-common                                    4.4.2-4                                       Shared files for PyQt4
ii  python-reportlab                                     2.1dfsg-2                                     ReportLab library to create PDF documents using Python
ii  python-selinux                                       2.0.65-4                                      Python bindings to SELinux shared libraries
ii  python-semanage                                      2.0.25-1                                      Python bindings  for SELinux policy manipulation tools
ii  python-sepolgen                                      1.0.11-4                                      A Python module used in SELinux policy generation
ii  python-simplejson                                    1.9.2-1                                       Simple, fast, extensible JSON encoder/decoder for Python
ii  python-sip4                                          4.7.6-1                                       Python/C++ bindings generator runtime library
ii  python-support                                       0.8.6                                         automated rebuilding support for Python modules
ii  python-tk                                            2.5.2-1                                       Tkinter - Writing Tk applications with Python
ii  python-tk-dbg                                        2.5.2-1                                       Tkinter - Writing Tk applications with Python (debug extension)
ii  python-tksnack                                       2.2.10-dfsg1-7                                Sound extension to Tcl/Tk and Python/Tkinter - Python library
ii  python-uno                                           1:2.4.1-8                                     Python interface for OpenOffice.org
ii  python-wxgtk2.6                                      2.6.3.2.2-2                                   wxWidgets Cross-platform C++ GUI toolkit (wxPython binding)
ii  python-wxgtk2.6-dbg                                  2.6.3.2.2-2                                   wxWidgets Cross-platform C++ GUI toolkit (wxPython binding, debug ve
ii  python-wxgtk2.8                                      2.8.7.1-1                                     wxWidgets Cross-platform C++ GUI toolkit (wxPython binding)
ii  python-wxgtk2.8-dbg                                  2.8.7.1-1                                     wxWidgets Cross-platform C++ GUI toolkit (wxPython binding, debug ve
ii  python-wxtools                                       2.6.3.2.2-2                                   wxWidgets Cross-platform C++ GUI toolkit (wxPython common files)
ii  python-wxversion                                     2.8.8.1-0                                     wxWidgets Cross-platform C++ GUI toolkit (wxPython version selector)
ii  python2.4                                            2.4.5-5                                       An interactive high-level object-oriented language (version 2.4)
ii  python2.4-dev                                        2.4.5-5                                       Header files and a static library for Python (v2.4)
ii  python2.4-minimal                                    2.4.5-5                                       A minimal subset of the Python language (version 2.4)
ii  python2.5                                            2.5.2-11                                      An interactive high-level object-oriented language (version 2.5)
ii  python2.5-dbg                                        2.5.2-11                                      Debug Build of the Python Interpreter (version 2.5)
ii  python2.5-dev                                        2.5.2-11                                      Header files and a static library for Python (v2.5)
ii  python2.5-minimal                                    2.5.2-11                                      A minimal subset of the Python language (version 2.5)
A voir également:

4 réponses

Utilisateur anonyme
6 sept. 2008 à 12:08
from Tkinter import *

root = Tk()

image = PhotoImage(file='toto.gif')

canvas = Canvas(root, width=1, height=1)

canvas.pack(fill=BOTH, expand=1)

canvas.create_image(0, 0, image=image, anchor=NW)

canvas.create_text(0, 20, text='Woohoo!', anchor=W)

root.geometry('80x80')

root.mainloop()
1
Rejoignez-nous