forked from buckyroberts/Source-Code-from-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24_dialogCustom.py
More file actions
49 lines (34 loc) · 1.45 KB
/
Copy path24_dialogCustom.py
File metadata and controls
49 lines (34 loc) · 1.45 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
42
43
44
45
46
47
48
49
from gi.repository import Gtk
class MainWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Dialog Example")
self.set_default_size(200, 100)
self.set_border_width(30)
button = Gtk.Button("Open a PopUp")
button.connect("clicked", self.button_clicked)
self.add(button)
def button_clicked(self, widget):
dialog = PopUp(self)
# User can't interact with main window until dialog returns something
response = dialog.run()
if response == Gtk.ResponseType.OK:
print("You clicked the OK button")
elif response == Gtk.ResponseType.CANCEL:
print("You clicked the CANCEL button")
dialog.destroy()
class PopUp(Gtk.Dialog):
def __init__(self, parent):
# self, title, parent, flags (MODAL prevent interaction with main window until dialog returns), buttons
Gtk.Dialog.__init__(self, "PopUp Title", parent, Gtk.DialogFlags.MODAL,
("Custom cancel text", Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK))
self.set_default_size(200, 100)
self.set_border_width(10)
# Content area (area above buttons)
area = self.get_content_area()
area.add(Gtk.Label("Wow that's so amazing, you can open a pop up."))
self.show_all()
win = MainWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()