PYGLET - On Hide Event

PYGLET - On Hide Event

pyglet is a Python library for multimedia and windowed application development. In pyglet, you can handle various window events, such as when the window is resized, shown, or hidden.

The on_hide event is triggered when the window is hidden. To handle this event, you can override the on_hide method in your window class.

Here's a simple example demonstrating how to handle the on_hide event using pyglet:

import pyglet class CustomWindow(pyglet.window.Window): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def on_draw(self): self.clear() pyglet.text.Label("Hello, pyglet!").draw() def on_hide(self): print("Window is hidden.") def on_show(self): print("Window is shown.") # Create an instance of the custom window window = CustomWindow(400, 300, "PYGLET - On Hide Event") @window.event def on_key_press(symbol, modifiers): if symbol == pyglet.window.key.H: print("Hiding window.") window.set_visible(False) # This triggers the on_hide event. elif symbol == pyglet.window.key.S: print("Showing window.") window.set_visible(True) # This triggers the on_show event. pyglet.app.run() 

In this example, when you press the "H" key, the window is hidden, triggering the on_hide event. Similarly, when you press the "S" key, the window is shown, and you can also handle the on_show event.

Remember, to effectively "hide" a window, you can use the set_visible(False) method, and to show it, you can use set_visible(True). These actions will trigger the on_hide and on_show events, respectively.


More Tags

oppo kubectl ignore-case format angular6 ant access-keys ilmerge access-control tempus-dominus-datetimepicker

More Programming Guides

Other Guides

More Programming Examples