Bonjour,

Voici 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
 
from Tkinter import *
from PIL import Image, ImageTk
import tkFileDialog
import os
 
def OpenFileA():
    fileA = tkFileDialog.askopenfile(parent=frame1,mode='rb',title='Choose File A')
    if fileA != None:
        print fileA
        dir_path = os.path.dirname(os.path.abspath(__file__))
        print(dir_path)
 
def OpenFileB():
    fileB = tkFileDialog.askopenfile(parent=frame1,mode='rb',title='Choose File B')
    if fileB != None:
        data = fileB.read()
        fileB.close()
        print "J'ai lu %d octets du fichier" % len(data)
 
frame1 = Tk()
frame1.geometry("450x600+10+10")
frame1.title('Boolean v1.0')
 
canvas_header = Canvas(frame1,width=400, height=200)
#Header = Frame(frame1, width=400, height=100).pack(side='top')
logo = ImageTk.PhotoImage(Image.open("boolean1.0.png"))
canvas_header.create_image(0, 25, anchor=NW, image=logo)
canvas_header.pack(side=TOP, padx=5, pady=5)
 
 
Cadre_1 = Frame(frame1, width=400, height=100)
Cadre_1.pack(side='top')
 
fileA = Label(Cadre_1, text="File A").grid(row=0,column=0)
entA = Entry(Cadre_1, width=40).grid(row=0,column=1, pady=10)
open_fileA = Button(Cadre_1, text='SELECT', width=10, height=1, command = OpenFileA).grid(row=0, column=2)
 
fileB = Label(Cadre_1, text="File B").grid(row=1,column=0)
entB = Entry(Cadre_1, width=40).grid(row=1,column=1, pady=10)
open_fileB = Button(Cadre_1, text='SELECT', width=10, height=1, command = OpenFileB).grid(row=1, column=2)
 
photo1 = ImageTk.PhotoImage(Image.open("A+B.png"))
photo2 = ImageTk.PhotoImage(Image.open("A-B.png"))
photo3 = ImageTk.PhotoImage(Image.open("AB.png"))
photo4 = ImageTk.PhotoImage(Image.open("B-A.png"))
 
canvas = Canvas(frame1,width=450, height=60)
canvas.create_image(90, 5, anchor=NW, image=photo1)
canvas.create_image(160, 5, anchor=NW, image=photo2)
canvas.create_image(230, 5, anchor=NW, image=photo3)
canvas.create_image(300, 5, anchor=NW, image=photo4)
canvas.pack(side=TOP, padx=5, pady=5)
 
Cadre_2 = Frame(frame1, width=250, height=10)
Cadre_2.pack_propagate(False)
Cadre_2.pack(side=TOP)
 
var_choix = StringVar()
 
choix_rouge = Radiobutton(Cadre_2,variable=var_choix, value="1")
choix_vert = Radiobutton(Cadre_2, variable=var_choix, value="2")
choix_bleu = Radiobutton(Cadre_2, variable=var_choix, value="3")
choix_gris = Radiobutton(Cadre_2, variable=var_choix, value="4")
 
choix_rouge.pack(side='left', padx=10)
choix_vert.pack(side='left', padx=30)
choix_bleu.pack(side='left', padx=10)
choix_gris.pack(side='right', padx=5)
 
 
 
footer_Button = Frame(frame1, width =350, height =50)
footer_Button.pack_propagate(False)
footer_Button.pack(side='bottom', pady=20)
 
Exit_Button = Button(footer_Button, text='-EXIT-', width=10, height=5,command = frame1.destroy)
Exit_Button.pack(side='left', padx=5, pady=5)
 
Apply_Button = Button(footer_Button, text='-APPLY-', width=10, height=5, command = frame1.destroy)
Apply_Button.pack(side='right', padx=5, pady=5)
 
 
frame1.mainloop()
Alors mon soucis est de récupérer le chemin du fichier sélectionné lorsque je clic sur le bouton SELECT.

ce que j'ai expérimenté fonctionne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
def OpenFileA():
    fileA = tkFileDialog.askopenfile(parent=frame1,mode='rb',title='Choose File A')
    if fileA != None:
        print fileA
        dir_path = os.path.dirname(os.path.abspath(__file__))
        print(dir_path)
sauf que le fichier que je souhaite sélectionné ne se trouve pas forcément là où le code est lancé, et os.path.dirname(os.path.abspath(__file__)) retourne le chemin du fichier python.

une idée ?

Merci d'avance.

PS : Je suis sous Windows pour l'instant, mais le code a vocation à tourner sous Linux/Mac OSX également.