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
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
import Tkinter as TK
import tkFileDialog as FD
class TkFileDialogExample(TK.Tk):
"""
cette classe bla bla bla... explications
"""
def __init__(self):
# superclass inits
TK.Tk.__init__(self)
# member inits
self.file_in = ""
self.file_out = ""
# widget inits
TK.Label(
self,
text="Input file",
).grid(row=0, column=0, sticky=TK.W)
self.input_tb = TK.Entry(self, width=30)
self.input_tb.grid(row=0, column=1)
TK.Button(
self,
text="browse",
command=self.dlg_file_open, # avoid confusing names /!\
).grid(row=0, column=2)
TK.Label(
self,
text="Output file",
).grid(row=1, column=0, sticky=TK.W)
self.output_tb = TK.Entry(self, width=30)
self.output_tb.grid(row=1, column=1)
TK.Button(
self,
text="browse",
command=self.dlg_file_save_as,
).grid(row=1, column=2)
TK.Button(
self,
text="send",
command=self.send,
).grid(row=2, column=1)
# end def
def dlg_file_open(self):
"""
cette méthode bla bla bla... explications
"""
self.file_in = FD.askopenfilename(
filetypes=[("all files", ".*"), ("text files", ".txt")],
)
self.input_tb.delete(0, TK.END)
self.input_tb.insert(0, self.file_in)
# end def
def dlg_file_save_as(self):
"""
cette méthode bla bla bla... explications
"""
self.file_out = FD.asksaveasfilename(
filetypes=[("all files", ".*"), ("text files", ".txt")],
defaultextension=".txt",
initialfile="myfile.txt",
)
self.output_tb.delete(0, TK.END)
self.output_tb.insert(0, self.file_out)
# end def
def send(self):
"""
cette méthode bla bla bla... explications
"""
print "input file:", self.file_in
print "output file:", self.file_out
# end def
# end class TkFileDialogExample
if __name__ == "__main__":
TkFileDialogExample().mainloop()
# end if |
Partager