You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am a newbie and trying to setup a chat example in the controls-gallery example. Any help would be appreciated. I am stuck at the pubsub call. Since its accesible as page.pubsub but since page is directly not callable in the example()
Here is my code
import asyncio
import flet as ft
name = "Chat example"
def example():
# subscribe to broadcast messages
def send_click(e):
print("reached here")
e.control.page.pubsub.send_all(f"{user.value}: {message.value}")
# clean up the form
message.value = ""
def on_message(msg):
messages.controls.append(ft.Text(msg))
page.update() # this is where its going wrong
page.pubsub.subscribe(on_message) # this is where its going wrong
messages = ft.Column()
user = ft.TextField(hint_text="Your name", width=150)
message = ft.TextField(hint_text="Your message...", width=150) # fill all the space
send = ft.ElevatedButton("Send", on_click=send_click)
row0 = ft.Row([user, message, send],wrap=True)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am a newbie and trying to setup a chat example in the controls-gallery example. Any help would be appreciated. I am stuck at the pubsub call. Since its accesible as page.pubsub but since page is directly not callable in the example()
Here is my code
import asyncio
import flet as ft
name = "Chat example"
def example():
# subscribe to broadcast messages
def send_click(e):
print("reached here")
e.control.page.pubsub.send_all(f"{user.value}: {message.value}")
# clean up the form
message.value = ""
def on_message(msg):
messages.controls.append(ft.Text(msg))
page.update() # this is where its going wrong
page.pubsub.subscribe(on_message) # this is where its going wrong
messages = ft.Column()
user = ft.TextField(hint_text="Your name", width=150)
message = ft.TextField(hint_text="Your message...", width=150) # fill all the space
send = ft.ElevatedButton("Send", on_click=send_click)
row0 = ft.Row([user, message, send],wrap=True)
Beta Was this translation helpful? Give feedback.
All reactions