Bonjour,
mon programme consiste à faire une fenetre dans laquelle il y aurais un menu bar et je rencontre quelques difficultés:
1)je n'arrive pas à afficher mon menu bar en haut de la fenetre.pour l'instant il est tout en abs de la fenetre et de façon verticale(moi je veux en haut et de façon horizontale);j'ai essayé plusieurs methode pack(padx padx anchor...) et grid(colomun,row) mais ça n'a rien donné.

2) dans mon menu vous verrez qu'il ya une option Help, on y trouve une fonction "Documentationonline"(dans le code c'est la fonction doc), je veux que qu'elle redirige l'utilisateur vers le site que je veux uen fois qu'il a clicé dessus.

si vous pouvez m'aider sur ces deux choses!!!!!!!!!!!!!

Merci bcp

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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
from Tkinter import*
import os
import urllib2, httplib
import win32clipboard as w
import Win32con
from tkFileDialog import askopenfilename
 
 
 
class MenuBar(Frame):
	def __init__(self, boss):
		Frame.__init__(self, borderwidth=2)
 
		self.lab=Label(self, text='Proj',fg='red',font=('Comic Sans MS',11))
		self.lab.pack(padx=1,pady=1)
		self.E_1=Entry(self, textvariable=boss.fichname)
		self.E_1.pack(pady=1)
 
		self.lab=Label(self, text='Output',fg='red', font=('Comic Sans MS',11))
		self.lab.pack(padx=2,pady=2)
		self.E_2=Entry(self, textvariable=boss.output1)
		self.E_2.pack(pady=2)
 
		self.lab=Label(self, text='Plot',fg='red', font=('Comic Sans MS',11))
		self.lab.pack(padx=3,pady=3)
		self.E_3=Entry(self, textvariable=boss.plot1)
		self.E_3.pack(pady=3)
 
		self.lab=Label(self, text='Intpar',fg='red', font=('Comic Sans MS',11))
		self.lab.pack(padx=4,pady=5)
		self.E_4=Entry(self, textvariable=boss.intpar1)
		self.E_4.pack(pady=4)
 
		self.lab=Label(self, text='Doublepar',fg='red', font=('Comic Sans MS',11))
		self.lab.pack(padx=5,pady=6)
		self.E_5=Entry(self, textvariable=boss.doublepar1)
		self.E_5.pack(pady=5)
 
		self.lab=Label(self, text='ComplexparRe',fg='red', font=('Comic Sans MS',11))
		self.lab.pack(padx=6,pady=7)
		self.E_6=Entry(self, textvariable=boss.complexpar1)
		self.E_6.pack(pady=6)
 
		self.lab=Label(self, text='ComplexparIm',fg='red', font=('Comic Sans MS',11))
		self.lab.pack(padx=7,pady=8)
		self.E_7=Entry(self, textvariable=boss.complexpar2)
		self.E_7.pack(pady=7)
 
		self.lab=Label(self, text='Meshfile',fg='red', font=('Comic Sans MS',11))
		self.lab.pack(padx=9,pady=10)
		self.E_8=Entry(self, textvariable=boss.meshfile1)
		self.E_8.pack(pady=7)
 
		self.lab=Label(self, text='Auxfile',fg='red', font=('Comic Sans MS',11))
		self.lab.pack(padx=9,pady=10)
		self.E_9=Entry(self, textvariable=boss.auxfile1)
		self.E_9.pack(pady=9)
 
 
 
 
		self.bou1=Button(self, text='run',command=boss.run)
		self.bou1.pack(side=LEFT,padx='20',pady='20')
 
		self.bou2=Button(self, text='Fill',command=boss.remplir)
		self.bou2.pack(side=LEFT,padx='25',pady='25')
 
		self.bou3=Button(self, text='close', command = self.destroy)
		self.bou3.pack(side=LEFT,padx='30',pady='30')
 
		#menu #
		fileMenu = Menubutton(self , text = 'File')
		fileMenu.pack(anchor=W,pady='2')
		edit = Menubutton(self , text='Edit')
		edit.pack(anchor=W,pady='2')
		execute = Menubutton(self , text = 'Execute')
		execute.pack(anchor=N,pady='4')
		help = Menubutton(self , text = 'Help')
		help.pack(anchor=N,pady='6')
 
		me1= Menu(fileMenu)
		#me1.add_command(label ='Open', underline =0, command = boss.ouvrir)
		me1.add_command(label ='Test', underline =0, command = boss.test)
 
		me2=Menu(edit)
		me2.add_command(label='Copy', underline =0, command = boss.copier)
		me2.add_command(label='Paste', underline =0, command = boss.coller)
		#me2.add_command(label='Cancel',underline=0,command=boss.annuler)
		#me2.add_command(label='restor',underline=0,command=boss.retablir)
		#m2.add_command(label='Selection', underline =0, command = boss.selectionner)
 
		me3= Menu(execute)
		me3.add_command(label='Run', underline =0, command = boss.run)
 
		me4=Menu(help)
		me4.add_command(label='Online documentation' , underline =0, command = boss.doc)
 
 
 
		fileMenu.configure(menu = me1)
		edit.configure(menu=me2)
		execute.configure(menu=me3)
		help.configure(menu=me4)
 
class Application(Frame):
 
	def __init__(self, boss =None):
		Frame.__init__(self)
 
		self.master.title('resolution de la demo EC2D')
 
		#self.text_defaut="aucun fichier ouvert!"
		#self.lab_fichier = Label(self)
		#self.lab_fichier.pack(padx=5, pady=5)
		self.fichname = StringVar()
		self.output1=StringVar()
		self.plot1=StringVar()
		self.intpar1=StringVar()
		self.doublepar1=StringVar()
		self.complexpar1=StringVar()
		self.complexpar2=StringVar()
		self.meshfile1=StringVar()
		self.auxfile1=StringVar()
 
		self.mBar = MenuBar(self)
		self.mBar.pack()
		self.can = Text(self,state=DISABLED,height=3,fg='black'); 
		self.can.pack()
		self.pack()
 
 
	#def ouvrir(self):
		#name = askopenfilenames(filetypes = [("All", "*"),("ofeli","*.m;*.dat;*.c;*.txt")])
 
		# si  l'utilisateur a bien selectionner un fichier
		#if name:
			#try:
				#fichier = open(name, "r")
				#fichier = open(name1,"r")
				#self.meshfile1.set(name)
				#self.auxfile1.set(name1)
				#except IOError:
					#text1=Label(self, text='Error, this file can not be opened!', fg='red')
					#lab_fichier.config(text= "Error,this file can not be opened !")
					#print "Error, this file can not be opened!"
			#else:
					#text2=Label(self, text=' this file can  be opened!', fg='red')
					#lab_fichier.config(text= " This file can be opened")
					#print "this file can be opened!!"
					#fichier.close()
		# si l'utilisateur à cliquer sur annuler
		#else:
			#lab_fichier.config(text="no file selected") 
			#print "no file selected"
 
	def remplir(self):
		name = askopenfilename(filetypes = [("all","*"),("ofeli","*.dat")])
		if name:
			try:
				fichier = open(name,"r")
			except IOError:
				self.can.insert("1.0", "Error this file can not be opened\n");
			else:
					#obtenir le contenu du fichier sous forme d'une liste de lignes
					L=fichier.readlines()
					#on ferme le fichier
					fichier.close()
					#print L
					#print
					#on retir les caracters de fin de ligne'\r' et/ou '\n'
					L=[x.rstrip('\r\n') for x in L]
					#print L
					#print
					#on transforme chaque ligne en sous -liste[clé, valeur]
					L=[x.split() for x in L]
					#print L
					#print
					#elimine la premiere et derniere ligne
					L=L[1:-1]
					#print L
					#print
					#elimine les lignes de commentaires
					L=[x for x in L if x[0]!="#"]
					print L
 
					a= L[0][1]
					self.fichname.set(a)
					b=L[1][1]
					self.output1.set(b)
					c=L[2][1]
					self.plot1.set(c)
					d=L[3][1]
					self.intpar1.set(d)
					e=L[4][1]
					self.doublepar1.set(e)
					f=L[5][1]
					self.complexpar1.set(f)
					i=L[5][2]
					self.complexpar2.set(i)
					g=L[6][1]
					self.meshfile1.set(g)
					h=L[7][1]
					self.auxfile1.set(h)
 
					#print a
 
 
		else:
				print "no file selected!"
 
 
	def test(self) :
 
		fichier1=self.fichname.get()
		taille1=len(fichier1)
		fichier2=self.meshfile1.get()
		taille2=len(fichier2)
		fichier3=self.auxfile1.get()
		taille3=len(fichier3)
 
		self.message("test\n")
		if fichier1:
 
			try:
				fich1 = open('%s'%(fichier1),'r')
			except IOError:
				self.message("error1\n")
			else:
				if (str(fich1.readline())) != '#PARAM!\n' :
 
							self.message("Error, the written name isn't a datafile\n")
							self.E_1.delete(0,taille1)
							#fich1.close()
				else:
 
					try:
						   fich2 = open('%s'%(fichier2),'r')
					except IOError:
						self.message("error2\n")
					else:
					    if (str(fich2.readline())) != '#MESH!\n' :
									                self.message("Error, the written name isn't a meshfile\n")
									                self.E_8.delete(0,taille2)
													#fich2.close()
					    else:
						    try:
							    fich3 = open('%s'%(fichier3),'r')
						    except IOError:
						              self.message("error3\n")
						    else:
						        if (str(fich3.readline())) != '#NODE_FIELD!\n' :
 
									                                        self.message("Error, the written name isn't a auxfile\n")
									                                        self.E_9.delete(0,taille3)
																			#fich3.close()
						        else:
							        self.message("ok\n")
									#fich2.close()
									#fich3.close()
 
	def message(self, text):
		self.can.config(state=NORMAL)
		self.can.insert(END,text)
		self.can.config(state=DISABLED)
 
	def doc(self):
 
		httplib.HTTPConnection.debuglevel = 1           
		request = urllib2.Request('http://www.ofeli.net') 
		opener = urllib2.build_opener()
		f = opener.open(request)
 
 
	def copier(self):
		w.openClipboard()
		d=GetClipboardData(win32con.CF_TEXT)
		w.CloseClipboard()
		return d
 
 
	def coller(self):
		w.openclipboard()
		w.EmptyClipboard()
		w.SetClipboardData(aType,aString)
		w.closeClipboard()
 
 
	#def annuler(self):
 
 
	#def retablir(self):
 
 
	#def seletionner(self):
 
 
 
	def run(self) :
		name=self.fichname.get()
		file = open("%s"%(name),'w')
 
		file.write('#PARAM!\n')
		file.write('Proj %s\n'%(name))
		output = self.output1.get()
		file.write('Output %s\n'%(output))
		plot = str(self.plot1.get())
		file.write('Plot %s\n'%(plot))
		file.write('#Voltage flag\n')
		intpar = str(self.intpar1.get())
		file.write('IntPar %s\n'%(intpar))
		file.write('#Abgular frenquency\n')
		doublepar = str(self.doublepar1.get())
		file.write('DoublePar %s\n'%(doublepar))
		file.write('#Voltage\n')
		complexparre= str(self.complexpar1.get())
		complexparim= str(self.complexpar2.get())
		file.write('ComplexPar %s %s\n'%(complexparre,complexparim))
		meshfile = self.meshfile1.get()
		file.write('MeshFile /python24/projet/ofeli/tests/demos/electromagnetics/eddycurrent2d-1/proj.m0/%s\n'%(meshfile))
		auxfile = self.auxfile1.get()
		file.write('AuxFile /python24/projet/ofeli/tests/demos/electromagnetics/eddycurrent2d-1/proj.m1/ %s\n'%(auxfile))
		file.write('EOF\n')
 
		file.close()
 
		#fichier = self.filename.get()
		os.system((" C:/python24/projet/ofeli/bin/ec2d1 C:/python24/projet/ofeli/tests/demos/electromagnetics/eddycurrent2d-1/%s.dat"%(name)))
 
if __name__ == '__main__':
	app = Application()
 
 
 
	app.mainloop()