bonsoir a tous,je suis sous idle 2.7, j'ai un soucis pour l'insertion d'une image dans le script:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Attrapez moi avec Pmw #
from Tkinter import *
import Pmw
from random import randrange
 
Pmw.initialise()
coul =['sienna','maroon','brown','pink','tan','wheat','gold','orange','plum',
        'red','khaki','indian red','thistle','firebrick','salmon','coral']
 
class FenPrinc(Pmw.ScrolledCanvas):
        """Fenêtre principale: canevas extensible avec barres de défilement"""
        def __init__(self):
                Pmw.ScrolledCanvas.__init__(self, usehullsize =1, hull_width =500,
                                        hull_height =300, canvas_bg ='grey40', canvasmargin =10,
                                        labelpos =N, label_text ='Attrapez le bouton !',
                                        borderframe =1, borderframe_borderwidth =3)
                # Les options ci-dessous doivent être précisées après initialisation :
                self.configure(vscrollmode ='dynamic', hscrollmode ='dynamic')
                self.pack(padx =5, pady =5, expand =YES, fill =BOTH)
 
                self.can = self.interior()                      # accès au composant canevas
                # Décor : tracé d'un série d'ellipses aléatoires :
                for r in range(80):
                        x1, y1 = randrange(-800, 800), randrange(-800, 800)
                        x2, y2 = x1 + randrange(40,300), y1 + randrange(40,300)
                        couleur = coul[randrange(0,16)]
                        self.can.create_oval(x1, y1, x2, y2, fill=couleur, outline='black')
                # Ajout d'une petite image GIF:
                self.img = PhotoImage(file = 'linux2.gif')
                self.can.create_image(50, 20, image =self.img)
                # dessin du bouton à attraper :
                self.x, self.y = 50, 100
                self.bou = Button(self.can, text ="Start", command =self.start)
                self.fb = self.can.create_window(self.x, self.y, window =self.bou)
                self.resizescrollregion()
 
        def anim(self):
                if self.run ==0:
                        return
                self.x += randrange (-60, 61)
                self.y += randrange (-60, 61)
                self.can.coords(self.fb, self.x, self.y)
                self.configure(label_text = 'Cherchez en %s %s' % (self.x, self.y))
                self.resizescollregion()
                self.after(250, self.anim)
 
        def stop(self):
                self.run =0
                self.bou.configure(text ="Restart", command =self.start)
 
        def start(self):
                self.bou.configure(text ="Attrapez moi !", command =self.stop)
                self.run =1
                self.anim()
 
#### Main Program ####
if __name__ == '__main__':
        FenPrinc().mainloop()
j'ai sa en message d'erreur:
File "/home/guillaume/attrapez moi.py", line 29, in __init__
self.img = PhotoImage(file = 'linux2.gif')
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 3247, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 3203, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
TclError: couldn't open "linux2.gif": no such file or directory
si quelqu'un pouvait m'orienter.
merci