Bonjour,
J'essaie de me lancer dans les interfaces graphiques avec Python. J'aimerais construire une fenêtre comportant plusieurs éléments, dont 1 bouton permettant d'ouvrir un fichier, un autre permettant de sauvegarder un fichier et un autre permettant d'appeler un script avec le nom des fichiers en paramètre.

Suite à mes recherches j'ai vu que ça pouvait se faire avec tkFileDialog, j'ai d'ailleurs trouvé un petit exemple ici.
Seul hic, je ne parviens pas à récupérer le chemin du fichier... Voici ce que j'ai fait :

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
import Tkinter, Tkconstants, tkFileDialog
 
class TkFileDialogExample(Tkinter.Frame):
 
	def __init__(self, root):
 
		Tkinter.Frame.__init__(self, root)
 
		# define buttons
		Tkinter.Label(self, text="Input file").grid(row=0, column=0, sticky='W')
		input_tb = Tkinter.Entry(self, width=20)
		input_tb.grid(row=0, column=1)
		Tkinter.Button(self, text='browse', command=self.askopenfilename, width=3).grid(row=0, column=2)
 
		Tkinter.Label(self, text="Output file").grid(row=1, column=0, sticky='W')
		output_tb = Tkinter.Entry(self, width=20)
		output_tb.grid(row=1, column=1)
		Tkinter.Button(self, text='browse', command=self.asksaveasfilename, width=3).grid(row=1, column=2)
 
		Tkinter.Button(self, text='send', command=self.send, width=5).grid(row=2, column=1)
 
	def askopenfilename(self):
		self.file_opt = options = {}
		options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
		return tkFileDialog.askopenfilename(**self.file_opt)
 
	def asksaveasfilename(self):
		self.file_opt = options = {}
		options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
		options['defaultextension'] = '.txt'
		options['initialfile'] = 'myfile.txt'
		return tkFileDialog.asksaveasfilename(**self.file_opt)
 
	def send(self):
		print 'Opened file: '
		print 'Saved file: '
 
if __name__=='__main__':
	root = Tkinter.Tk()
	TkFileDialogExample(root).pack()
	root.title("Test")
	root.geometry("300x100")
	root.mainloop()
Je ne sais pas quoi mettre dans mon print pour afficher les fichiers sélectionnés. Par ailleurs j'aimerais également mettre à jour les champs de text à gauche des boutons mais même problème.

Un petit coup de main ?
Merci !