-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathOpenFileDialog.py
More file actions
executable file
·40 lines (31 loc) · 1.12 KB
/
Copy pathOpenFileDialog.py
File metadata and controls
executable file
·40 lines (31 loc) · 1.12 KB
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
#!/usr/bin/env python3
# -*-coding:utf-8 -*
import os
import platform
import tkinter
import tkinter.filedialog
import tkinter.ttk
class Form1(tkinter.Tk):
def __init__(self):
super().__init__()
self.frame = tkinter.ttk.Frame(self)
self.frame.pack(fill = tkinter.BOTH, expand=1)
self.button = tkinter.ttk.Button(self.frame, command=self.OnButtonClick, text='File...')
self.button.place(x=10, y=10)
self.label = tkinter.ttk.Label(self.frame, text='File = ')
self.label.place(x=10, y=40)
self.geometry('300x300+200+100')
self.title('OpenFileDialog example')
def main(self=None):
form = Form1()
form.mainloop()
def OnButtonClick(self):
openFileOptions = {}
openFileOptions['filetypes'] = [("Text Files", "*.txt"), ("All Files", "*.*")]
openFileOptions['initialdir'] = os.path.join(os.environ["HOMEPATH" if platform.system() == 'Windows' else 'HOME'], "Desktop")
openFileOptions['parent'] = self
fileName = tkinter.filedialog.askopenfilename(**openFileOptions)
if fileName:
self.label['text'] = 'File = {}'.format(fileName)
if __name__ == '__main__':
Form1.main()