#!/usr/bin/env python from Tkinter import * import os from tkFileDialog import askopenfilename def ouvrir():#je n'arrive pas à recuperer la valeur selectionné nom = askopenfilename(filetypes = [("All", "*"),("ex2","*.m;*.c;*.txt")]) # si un l'utilisateur a bien sélectionner un fichier if nom: try: fichier = open(nom, "r") except IOError: print "Error,this file can not be opened !" else: print " This file can be opened" fichier.close() # si l'utilisateur à cliquer sur annuler else: print "No file selected !" def test() :#j'ai besoin de la valeur pour pouvoir lancer le test fichier = entree.get() taille = len(fichier) fich = open('%s'%(fichier),'r') if str(fich.readline()) != '#MESH!\n' : print "Error,this file is not a mesh file !" entree.delete(0,taille) else : print "You can execute" fich.close() def run() : fichier = entree.get() os.system(("C:/python24/projet/ex2 ~ex2/%s"%(fichier))) #if resultat == 0 #printf" execution reussie" #else #printf"erreur d'execution" fen = Tk() fen.title('ex2') text = Label(fen, text = 'Mesh File') text.grid() entree = Entry(fen) entree.grid(row = 0, column = 2) but1=Button(fen, text="Open", command=ouvrir) but1.grid(row = 1) but2 = Button(fen, text = 'Test', command = test) but2.grid(row = 1, column = 1) but3 = Button(fen, text = 'run', command = run) but3.grid(row = 1, column = 2) but4 = Button(fen, text = 'Close', command = fen.destroy) but4.grid(row = 1, column = 3) fen.mainloop()