Skip to content

How to pass params when switch_mode(create screen object)? #4480

Answered by TomJGooding
Yurii-huang asked this question in Q&A
Discussion options

You must be logged in to vote

I think the problem might be that you forgot to call `super().init(). Here's a quick example based on the code above which seems to work okay?

from textual.app import App, ComposeResult
from textual.widgets import Placeholder, Footer
from textual.screen import Screen


class Edit(Screen):
    def __init__(self, data: str):
        self.data = data
        super().__init__()

    def compose(self) -> ComposeResult:
        yield Placeholder(self.data)
        yield Footer()


class ModesApp(App):
    BINDINGS = [
        ("f", "switch_mode('foo')", "Foo"),
        ("b", "switch_mode('bar')", "Bar"),
        ("z", "switch_mode('baz')", "Baz"),
    ]

    MODES = {
        "foo": Edit("Foo")…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@Yurii-huang
Comment options

@TomJGooding
Comment options

Answer selected by Yurii-huang
@tsingwang
Comment options

@willmcgugan
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants