From 72bf9713a725b6d4cf180ffb83c500bfce7518eb Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 7 Jul 2016 17:07:29 +0200 Subject: [PATCH] first filedialog working --- array2xls.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 array2xls.py diff --git a/array2xls.py b/array2xls.py new file mode 100644 index 0000000..704c181 --- /dev/null +++ b/array2xls.py @@ -0,0 +1,53 @@ +import tkinter as tk + + +class StatusBar(tk.Frame): + + def __init__(self, master): + tk.Frame.__init__(self, master) + self.label = tk.Label(self, bd=1, relief=tk.SUNKEN, anchor=tk.SW) + self.label.pack(fill=tk.X) + self.pack(side=tk.BOTTOM, fill=tk.X) + + def set(self, text): + self.label.config(text=text) + self.label.update_idletasks() + + def clear(self): + self.label.config(text="") + self.label.update_idletasks() + + +class Application(tk.Frame): + + def __init__(self, master=None): + #master.geometry("500x500") + master.minsize(height=100, width=100) + tk.Frame.__init__(self, master) + self.pack(fill=tk.BOTH) + self.status = StatusBar(self.master) + self.create_widgets() + + def create_widgets(self): + self.btn_files = tk.Button(self, text="Select Files", command=self.selected_files) + self.btn_files.pack(side=tk.LEFT, pady=5, padx=5) + self.btn_quit = tk.Button(self, text="Quit", command=self.quit) + self.btn_quit.pack(side=tk.RIGHT, pady=5, padx=5) + + def selected_files(self): + opts = { + 'initialdir': '~', + 'filetypes': [('text files', '.txt'), ('python files', '.py')], + 'multiple':True} + result = tk.filedialog.askopenfilename(**opts) + print(type(result), ':', result) + + +if __name__ == '__main__': + root = tk.Tk() + app = Application(master=root) + app.mainloop() + try: + root.destroy() + except tk.TclError: + pass