Reputation: 23
Is there a way I can use the same button to connect and disconnect?
For this, I should be able to change button properties dynamically.
Connect -> Connected -> Disconnect.
these could be the state of the button.
Upvotes: 0
Views: 119
Reputation: 46
You can use partials to change the label of the button when it is pressed. The following code will display a button whose label will switch between "Connect" and "Disconnect" when pressed. Let me know if this fixes your issue.
from taipy.gui import Gui
connected = False
def button_press(state):
if not state.connected:
state.button_partial.update_content(
state, "<|Disconnect|button|on_action=button_press|>"
)
state.connected = True
else:
state.button_partial.update_content(
state, "<|Connect|button|on_action=button_press|>"
)
state.connected = False
page = """
<|part|partial={button_partial}|>
"""
gui = Gui(page)
button_partial = gui.add_partial("<|Connect|button|on_action=button_press|>")
gui.run()
Upvotes: 0