I'm looking to re-structure my flet app in a more OOP method as I increase the number of features.
How can I move things like callbacks out of my main()
function when I use them in flet.Checkbox
I can't add arguments (like page=page
) to the callbacks.
For example, here is my darkmode callback that when a user checks a box.
I'd like to have a file called callbacks.py
where I can put my dark_mode_callback
(and a lot of others) - and then import the module
import flet
def main(page):
settings = {'dark_mode': False}
def dark_mode_callback(_):
page.theme_mode = flet.ThemeMode.DARK if dark_mode_checkbox.value else flet.ThemeMode.LIGHT
page.update()
dark_mode_checkbox = flet.Checkbox(label="Dark Mode", value=settings.get('dark_mode', False), on_change=dark_mode_callback)
settings_controls = flet.Row([dark_mode_checkbox])
page.add(settings_controls)
if __name__ == "__main__":
flet.app(target=main)
Thank you