forked from buckyroberts/Source-Code-from-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path26_dialogFileChooser.py
More file actions
38 lines (27 loc) · 1.12 KB
/
Copy path26_dialogFileChooser.py
File metadata and controls
38 lines (27 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
from gi.repository import Gtk
class FileChooserWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="")
self.set_border_width(30)
layout = Gtk.Box(spacing=6)
self.add(layout)
button = Gtk.Button("Choose File")
button.connect("clicked", self.on_file_clicked)
layout.add(button)
# User clicked open file button
def on_file_clicked(self, widget):
# Gtk.FileChooserAction.SELECT_FOLDER
dialog = Gtk.FileChooserDialog("Select a file Hoss", self, Gtk.FileChooserAction.OPEN,
(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
response = dialog.run()
if response == Gtk.ResponseType.OK:
print("Open button clicked")
print("File selected: " + dialog.get_filename())
elif response == Gtk.ResponseType.CANCEL:
print("Cancel button clicked")
dialog.destroy()
window = FileChooserWindow()
window.connect("delete-event", Gtk.main_quit)
window.show_all()
Gtk.main()