19. Popovers

The Gtk.Popover is a separate window used for displaying additional information and is often used with button menus and context menus. Popovers are visually connected to a related widget with a small triangle. Their uses are similar to those of dialog windows with the advantage of being less disruptive and having a connection with the widget the popover is pointing to.

A Popover can be created with Gtk.Popover; for opening the popover use Gtk.Popover.popup().

19.1. Custom Popover

A widget can be added to a popover using Gtk.Container.add().

19.1.1. Beispiel

_images/popover_example.png
 1import gi
 2
 3gi.require_version("Gtk", "3.0")
 4from gi.repository import Gtk
 5
 6
 7class PopoverWindow(Gtk.Window):
 8    def __init__(self):
 9        Gtk.Window.__init__(self, title="Popover Demo")
10        self.set_border_width(10)
11        self.set_default_size(300, 200)
12
13        outerbox = Gtk.Box(spacing=6, orientation=Gtk.Orientation.VERTICAL)
14        self.add(outerbox)
15
16        self.popover = Gtk.Popover()
17        vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
18        vbox.pack_start(Gtk.ModelButton(label="Item 1"), False, True, 10)
19        vbox.pack_start(Gtk.Label(label="Item 2"), False, True, 10)
20        vbox.show_all()
21        self.popover.add(vbox)
22        self.popover.set_position(Gtk.PositionType.BOTTOM)
23
24        button = Gtk.MenuButton(label="Click Me", popover=self.popover)
25        outerbox.pack_start(button, False, True, 0)
26
27
28win = PopoverWindow()
29win.connect("destroy", Gtk.main_quit)
30win.show_all()
31Gtk.main()

19.3. Siehe auch