Replies: 2 comments 2 replies
-
I can also simply copy the entire |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yeah, actually. I dont know what's your goal exactly, but if you wish to simply have your class attached to the page, you could do something like this: import flet as ft
class MyClass:
def __init__(self):
super().__init__()
self.account = "text"
def get_text(self):
print(self.account)
def main(page: ft.Page):
page.my_class = MyClass()
print(page.my_class.account)
print(page.my_class.get_text())
page.add(ft.Text("Hello, World!"))
ft.app(main) |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question
I heavily use custom controllers, and I would be surprised if a developer decided to build their product in any other way than through custom controllers.
https://flet.dev/docs/getting-started/custom-controls/
At some point, I decided to rewrite one of the classes and thought it would be cool to have my own methods and attributes directly in the
ft.Page
instance.I really liked this idea, so I tried this:
However, I got this error:

Of course, there is a solution. I can do it this way (although VS Code won’t highlight the new attribute’s syntax as if I had assigned it in a class):
After several attempts to achieve this, I suspect that Flet already creates an instance of
ft.Page
, andft.app()
expects exactly this instance.I have two questions:
ft.Page
instance created? (If my suspicions are correct)ft.Page
?And as far as I remember from reading the documentation, it was mentioned that
ft.Page
is just likeft.Container
orft.Column
.Code sample
No response
Error message
No response
------------------------------------------------------
Beta Was this translation helpful? Give feedback.
All reactions