Bonjour a tous

Je suis débutant sur Python et pas tres habitue avec les gui mais j essaye d écrire un prog d analyse de fichiers d'instruments.
Pour cela je suis en train d écrire l'interface mais je voudrai afficher une image dans un canvas et je n y arrive pas dans mon code. Pourtant j y arrive normalement sans probleme dans les autres config. Mais la j essaye de passer par la technique des classes...
voila mon code :
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
!/usr/bin/env python
 
from Tkinter import *
 
 
class _Newform:
    def __init__(self, master):
        self.initComplete = 0
        frame = Frame(master, width=668, height=414)
        frame.pack()
        self.master = master
        self.x, self.y, self.w, self.h = -1,-1,-1,-1
        self.master.bind('<Enter>', self.bindConfigure)
 
#====================================================================================================#
#                                           TITRE DE LA FENETRE                                      #
#====================================================================================================#
        self.master.title("NewForm")
 
#====================================================================================================#
#                                          Definition des boutons                                    #
#====================================================================================================#
 
        self.Chargefichier_Button = Button(self.master,text="Button_1 text", width="15")
        self.Chargefichier_Button.place(x=12, y=324, width=102, height=25)
        self.Chargefichier_Button.bind("<ButtonRelease-1>", self.Chargefichier_Button_Click)
 
        self.Repertoire_Button = Button(self.master,text="Button_2 text", width="15")
        self.Repertoire_Button.place(x=12, y=288, width=103, height=26)
        self.Repertoire_Button.bind("<ButtonRelease-1>", self.Repertoire_Button_Click)
 
#====================================================================================================#
#                                          Definition du canvas image                                #
#====================================================================================================#
 
        self.can1 = Canvas(self.master, width =160, height =160,bg ='white')
 
        photo = PhotoImage(file ='cigogne.gif')
        item = self.can1.create_image(80, 80, anchor= CENTER, image =photo)
 
        self.can1.place(x=144, y=12)
 
#====================================================================================================#
#                                          Definition des Labels                                     #
#====================================================================================================#
 
 
        self.Fichier_Accelerometre_Label = Label(self.master,text="Fichier_Accelerometre", image="", width="15", relief="flat", anchor="center", justify="left")
        self.Fichier_Accelerometre_Label.place(x=48, y=180, width=145, height=26)
 
        self.Fichier_Instrumentation_Label = Label(self.master,text="Fichier_instrumentation", image="", justify="left", relief="flat", width="15")
        self.Fichier_Instrumentation_Label.place(x=48, y=204, width=160, height=23)
 
        self.Label_5 = Label(self.master,text="Label_5 text", width="15")
        self.Label_5.place(x=216, y=180, width=97, height=20)
 
        self.Label_6 = Label(self.master,text="Label_6 text", width="15")
        self.Label_6.place(x=216, y=204, width=97, height=20)
 
        self.Label_7 = Label(self.master,text="Label_7 text", width="15")
        self.Label_7.place(x=216, y=228, width=98, height=21)
 
        self.Label_8 = Label(self.master,text="Label_8 text", width="15")
        self.Label_8.place(x=216, y=252, width=98, height=21)
 
        self.Nom_Du_Fichier_Sauvegarde_Label = Label(self.master,text="Nom_du_fichier_sauvegarde", relief="flat", justify="left", anchor="center", width="15")
        self.Nom_Du_Fichier_Sauvegarde_Label.place(x=48, y=252, width=144, height=22)
 
        self.Repertoire_De_Travail_Label = Label(self.master,foreground="SystemButtonText", text="Repertoire_de_travail", width="15", relief="flat", anchor="center", justify="left")
        self.Repertoire_De_Travail_Label.place(x=48, y=228, width=145, height=23)
 
#====================================================================================================#
#                                          Definition des Radio Boutons                              #
#====================================================================================================#
 
        self.Radiobutton_1 = Radiobutton(self.master,text="Radiobutton_1 text", value="Radiobutton_1 value", width="15")
        self.Radiobutton_1.place(x=12, y=24, width=120, height=24)
        self.RadioGroup1_StringVar = StringVar()
        self.RadioGroup1_StringVar.set("Radiobutton_1 value")
        self.RadioGroup1_StringVar_traceName = self.RadioGroup1_StringVar.trace_variable("w", self.RadioGroup1_StringVar_Callback)
        self.Radiobutton_1.configure(variable=self.RadioGroup1_StringVar )
 
        self.Radiobutton_2 = Radiobutton(self.master,text="Radiobutton_2 text", image="", value="Radiobutton_2 value", indicatoron="1", width="15", justify="center")
        self.Radiobutton_2.place(x=12, y=60, width=120, height=24)
        self.Radiobutton_2.configure(variable=self.RadioGroup1_StringVar )
 
#====================================================================================================#
#                                          Definition du frame texte                                 #
#====================================================================================================#
 
        lbframe = Frame( self.master )
        self.Text_1_frame = lbframe
        scrollbar = Scrollbar(lbframe, orient=VERTICAL)
        self.Text_1 = Text(lbframe, width="40", height="12", yscrollcommand=scrollbar.set)
        scrollbar.config(command=self.Text_1.yview)
        scrollbar.pack(side=RIGHT, fill=Y)
        self.Text_1.pack(side=LEFT, fill=BOTH, expand=1)
 
        self.Text_1_frame.place(x=360, y=12, width=222, height=159)
        self.master.resizable(0,0) # Linux may not respect this
 
 
 
#====================================================================================================#
#                                          Definition du menu                                        #
#====================================================================================================#
        self.menuBar = Menu(master, relief = "raised", bd=2)
 
        top_Init = Menu(self.menuBar, tearoff=0)
 
        top_Init.add("command", label = "Fichier Acc", command = self.menu_Init_Fichier_Acc)
        top_Init.add("command", label = "Fichier Instrumentation", command = self.menu_Init_Fichier_Instrumentation)
        top_Init.add("command", label = "Repertoire travail", command = self.menu_Init_Repertoire_travail)
        top_Init.add("command", label = "Sauvegarde Fichier", command = self.menu_Init_Sauvegarde_Fichier)
        top_Init.add("command", label = "Quit", command = self.master.quit)
        self.menuBar.add("cascade", label="Init", menu=top_Init)
 
        top_About = Menu(self.menuBar, tearoff=0)
 
        top_About.add("command", label = "Help", command = self.menu_About_Help)
        self.menuBar.add("cascade", label="About", menu=top_About)
 
        master.config(menu=self.menuBar)
 
 
#====================================================================================================#
#                                          Definition des fonctions                                  #
#====================================================================================================#
 
 
 
    def menu_Init_Fichier_Acc(self):
        pass
        print "called menu_Init_Fichier_Acc"
 
 
    def menu_Init_Fichier_Instrumentation(self):
        pass
        print "called menu_Init_Fichier_Instrumentation"
 
 
    def menu_Init_Repertoire_travail(self):
        pass
        print "called menu_Init_Repertoire_travail"
 
    def menu_Init_Sauvegarde_Fichier(self):
        pass
        print "called menu_Init_Sauvegarde_Fichier"
 
 
    def menu_About_Help(self):
        pass
        print "called menu_About_Help"
 
    def bindConfigure(self, event):
        if not self.initComplete:
            self.master.bind("<Configure>", self.Master_Configure)
            self.initComplete = 1
 
 
    def Master_Configure(self, event):
        pass
        if event.widget != self.master:
            if self.w != -1:
                return
        x = int(self.master.winfo_x())
        y = int(self.master.winfo_y())
        w = int(self.master.winfo_width())
        h = int(self.master.winfo_height())
        if (self.x, self.y, self.w, self.h) == (-1,-1,-1,-1):
            self.x, self.y, self.w, self.h = x,y,w,h
 
 
        if self.w!=w or self.h!=h:
            print "Master reconfigured... make resize adjustments"
            self.w=w
            self.h=h
 
    def Chargefichier_Button_Click(self, event): 
        pass
        print "executed method Chargefichier_Button_Click"
 
 
    def Repertoire_Button_Click(self, event):
        pass
        print "executed method Repertoire_Button_Click"
 
 
    def Canvas_1_Click(self, event): 
        pass
        print "executed method Canvas_1_Click"
        print "clicked in canvas at x,y =",event.x,event.y
        w = int(self.can1.cget("width"))
        h = int(self.can1.cget("height"))
        self.can1.create_rectangle((2, 2, w+1, h+1), outline="blue")
        self.can1.create_line(0, 0, w+2, h+2, fill="red")
        x = int(event.x)
        y = int(event.y)
        print "event x,y=",x,y
        self.can1.create_text(x,y, text="NE", fill="green", anchor=NE)
        self.can1.create_text(x,y, text="SW", fill="magenta", anchor=SW)
 
    def RadioGroup1_StringVar_Callback(self, varName, index, mode):
        pass
        print "RadioGroup1_StringVar_Callback varName, index, mode",varName, index, mode
        print "    new StringVar value =",self.RadioGroup1_StringVar.get()
 
 
 
 
def main():
    root = Tk()
    app = _Newform(root)
    root.mainloop()
 
if __name__ == '__main__':
    main()
il manque quelque chose pour rendre l image apparente mais je suis perdu
merci de votre aide

Patrice