Gtk.EventBox


Gtk.EventBox — A widget used to catch events for widgets which do not have their own window

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Bin
                    ╰── Gtk.EventBox

Functions:

Description:

The Gtk.EventBox widget is a subclass of GtkBin which also has its own window.

It is useful since it allows you to catch events for widgets which do not have their own window.


Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.EventBox.

  • Returns: a new Gtk.EventBox

set_above_child()

set_above_child (self, above_child:bool)

Set whether the event box window is positioned above the windowsof its child, as opposed to below it. If the window is above, allevents inside the event box will go to the event box. If the windowis below, events in windows of child widgets will first got to thatwidget, and then to its parents. The default is to keep the window below the child.

  • Since: 2.4

get_above_child()

get_above_child (self) -> bool

Returns whether the event box window is above or below thewindows of its child. See Gtk.EventBox:set_above_child()for details.

  • Returns: True if the event box window is above thewindow of its child

  • Since: 2.4


set_visible_window()

set_visible_window (self, visible_window:bool)

Set whether the event box uses a visible or invisible childwindow. The default is to use visible windows. In an invisible window event box, the window that theevent box creates is a GDK_INPUT_ONLY window, whichmeans that it is invisible and only serves to receiveevents. A visible window event box creates a visible (GDK_INPUT_OUTPUT)window that acts as the parent window for all the widgetscontained in the event box. You should generally make your event box invisible ifyou just want to trap events. Creating a visible windowmay cause artifacts that are visible to the user, especiallyif the user is using a theme with gradients or pixmaps. The main reason to create a non input-only event box is ifyou want to set the background to a different color ordraw on it. There is one unexpected issue for an invisible event box that has itswindow below the child. (See Gtk.EventBox:set_above_child().)Since the input-only window is not an ancestor window of any windowsthat descendent widgets of the event box create, events on thesewindows aren’t propagated up by the windowing system, but only by GTK+.The practical effect of this is if an event isn’t in the eventmask for the descendant window (see `Gtk.Widget:add_events()`),it won’t be received by the event box. This problem doesn’t occur for visible event boxes, because inthat case, the event box window is actually the ancestor of thedescendant windows, not just at the same place on the screen.

  • Since: 2.4

get_visible_window()

get_visible_window (self) -> bool

Returns whether the event box has a visible window.See Gtk.EventBox:set_visible_window() for details.

  • Returns: True if the event box window is visible

  • Since: 2.4


Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

def event(eventbox, event):
    print("Event: %s" % event)

def event_press(eventbox, event):
    print("Button Press Event: %s" % event)

def event_release(eventbox, event):
    print("Button Release Event: %s" % event)

window = Gtk.Window()
window.set_title("EventBox")
window.set_default_size(200, 200)
window.connect("destroy", Gtk.main_quit)

eventbox = Gtk.EventBox()
eventbox.connect("event", event)
eventbox.connect("button-press-event", event_press)
eventbox.connect("button-release-event", event_release)
window.add(eventbox)

label = Gtk.Label("EventBox containing Label")
eventbox.add(label)

window.show_all()

Gtk.main()

results matching ""

    No results matching ""