-
|
Some background: Here is the issue: self.get_widget_by_id("my_select").disabled = True
# OR
self.query_one(Select).disabled = TrueIt should also be noted that I am creating the select with the following call (perhaps this is the issue): Select.from_values(my_values, id="my_select", classes="myclass")Other info: |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
|
I should also mention I am using python 3.9.14 on RHEL 9.1 and textual 0.47.1 |
Beta Was this translation helpful? Give feedback.
-
|
Do you think you could provide an MRE of the exact situation? For example, with this code: from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Button, Select
class DisableSelectApp(App[None]):
def compose(self) -> ComposeResult:
yield Button("Disable", id="disable")
yield Button("Enable", id="enable")
yield Select[int]((f"This is selection {n}", n) for n in range(20))
@on(Button.Pressed)
def set_select_disabled(self, event: Button.Pressed) -> None:
self.query_one(Select).disabled = event.button.id == "disable"
if __name__ == "__main__":
DisableSelectApp().run()I can disable and enable the |
Beta Was this translation helpful? Give feedback.
-
|
Yours worked properly on my machine. Here is the MRE: #!/usr/bin/env python3
import threading
import time
from textual import on
from textual.app import App, ComposeResult
from textual.widgets import Button, Select
class DisableSelectApp(App[None]):
def compose(self) -> ComposeResult:
yield Button("Start Process", id="start")
yield Select.from_values([str(i) for i in range(5)], id="my_select")
def on_mount(self) -> None:
self.process_running = False
threading.Thread(target=self.background_thread, daemon=True).start()
def background_thread(self):
while True:
if self.process_running:
self.get_widget_by_id("my_select").disabled = True
time.sleep(5)
self.process_running = False
self.get_widget_by_id("my_select").disabled = False
time.sleep(1)
@on(Button.Pressed)
def start_process(self, event: Button.Pressed) -> None:
self.process_running = True
if __name__ == "__main__":
DisableSelectApp().run()Note: if I change to disable/enable the button instead of the select, it performs as expected. |
Beta Was this translation helpful? Give feedback.
So the issue here is you're trying to interact with the Textual DOM from a thread, and doing things that block, etc.
To start with you may want to have a read of the guide to workers.