begin process at 2012 05 24 21:55:29
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Python

 > 

Divers

 > 

Débutant(e)

 > 

chargement d'une image


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

chargement d'une image

lundi 1 septembre 2008 à 18:39:46 | chargement d'une image

panthere007

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 <bound method PhotoImage.__del__ of <PIL.ImageTk.PhotoImage instance at 0xb6f0322c>> 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)


mercredi 3 septembre 2008 à 19:37:52 | Re : chargement d'une image

fred1599

Peux-tu nous donner le code en entier?

Quand on veut créer un canvas, on doit déjà creer sa fenetre

http://python.developpez.com/faq/?page=Canvas#CanvasImage


mercredi 3 septembre 2008 à 20:11:37 | Re : chargement d'une image

panthere007

Merci pour ta réponse.

j'ai déjà utiliser le code du lien que tu as donner mai sa ne me permet pas de mettre les contrôle en dessus, mai juste de dessiner le caneva qui va contenir l'image. les control eu seront systematiquement a coter.
samedi 6 septembre 2008 à 12:08:49 | Re : chargement d'une image

fred1599

Réponse acceptée !
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()


samedi 6 septembre 2008 à 18:04:33 | Re : chargement d'une image


Cette discussion est classée dans : image, for, python, ii, bindings


Répondre à ce message

Sujets en rapport avec ce message

FXP - FTP PYTHON [ par Dan17470 ] Bonsoir,Je transmets (webcam FTP) une image sur mon siteJe souhaite récupérer cette même image pour la transférer (FTP) sur un autre siteLe code suiva ^FTP - FXP PYTHON [ par Dan17470 ] Bonjour,Je transmets une image sur mon site (webcam - FTP, toutes les 6 secondes)Je souhaite transférer (FTP) cette même image toutes les minutes sur Python / SQLite / for...in... [ par samylatortue ] Bonjour à tous,je suis face à un problème depuis quelque jours...j'ai une base de donnée dans laquel il y a 2 tables j'aimerais prendre une partie des Comment creer une GUI en pure python ??? [ par pythux ] Bonjour a tous !!!Apres de nombreuse recherche infructueuses sur le net, je me tourne vers vous pour essayez de me donner quelque ellements de reponse python ou php ? [ par eric35 ] Salut J' hésite entre ces 2 langages ...Avant de choisir l'un ou l 'autre, pouvez vous me donner  à titre d 'exemple, quel serait le code pour lancer charger une image 3D [ par ghadroud ] Bonjour,Je suis sensée développer une application en python qui charge un image 3D et qui soit inclue dans la page web.Comment procéder a ca?merci Conversion de code C en Python [ par EvinVodKha ] Bonjour,J'ai environ 2500 lignes de code C à traduire rapidement en Python (homogénéisation du code d'un logiciel de 8000 lignes).Connaissez-vous un l Python 2.4 vers 2.5 Changement de code? [ par kididouille ] Bonjour,j'ai réalisé un programme avec python 2.4, il fonctionne tout va bien. On me demande de le faire en python 2.5 cela va t il impacter des chang lancer automatiquement une application python en .exe [ par cybersouris ] BonjourJ'ai une application compilée en python avec une extension .exe et j'essaie de la  lancer via mon navigateur web avec un javascript mais rien n python & pstricks [ par rbastian1 ] Bonjour, j'ai lu une proposition de Laurent Claessens comment écrire du PSTrickx en Python (je connais 'pyx'- mais je souhaite qq chose de plus simpl


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

Photothèque

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,406 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales