mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
input docs an exampels
This commit is contained in:
31
docs/examples/guide/input/mouse01.py
Normal file
31
docs/examples/guide/input/mouse01.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from textual.app import App, ComposeResult
|
||||
|
||||
from textual import events
|
||||
from textual.layout import Container
|
||||
from textual.widgets import Static, TextLog
|
||||
|
||||
|
||||
class PlayArea(Container):
|
||||
def on_mount(self) -> None:
|
||||
self.capture_mouse()
|
||||
|
||||
def on_mouse_move(self, event: events.MouseMove) -> None:
|
||||
self.screen.query_one(TextLog).write(event)
|
||||
self.query_one(Ball).offset = event.offset - (8, 2)
|
||||
|
||||
|
||||
class Ball(Static):
|
||||
pass
|
||||
|
||||
|
||||
class MouseApp(App):
|
||||
CSS_PATH = "mouse01.css"
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield TextLog()
|
||||
yield PlayArea(Ball("Textual"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = MouseApp()
|
||||
app.run()
|
||||
Reference in New Issue
Block a user