-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSaveFileDialog.py
More file actions
executable file
·41 lines (32 loc) · 1.17 KB
/
Copy pathSaveFileDialog.py
File metadata and controls
executable file
·41 lines (32 loc) · 1.17 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
41
#!/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):
saveFileOptions = {}
saveFileOptions['filetypes'] = [("Text Files", "*.txt"), ("All Files", "*.*")]
saveFileOptions['initialdir'] = os.path.join(os.environ["HOMEPATH" if platform.system() == 'Windows' else 'HOME'], "Desktop")
saveFileOptions['initialfile'] = 'MyFile.txt'
saveFileOptions['parent'] = self
fileName = tkinter.filedialog.asksaveasfilename(**saveFileOptions)
if fileName:
self.label['text'] = 'File = {}'.format(fileName)
if __name__ == '__main__':
Form1.main()