Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to restart the app by programming? #130

Open
BrentHuang opened this issue Apr 26, 2024 · 4 comments
Open

How to restart the app by programming? #130

BrentHuang opened this issue Apr 26, 2024 · 4 comments

Comments

@BrentHuang
Copy link

How to restart the app by programming?

If I have a restart menu item, or a pop-up box prompts the user to resetart.

@BrentHuang
Copy link
Author

# -*- coding: utf-8 -*-

import flet as ft
import sys
import os
import time


def restart_program():
    '''
    Restarts the current program.
    Note: this function does not return. Any cleanup action (like saving data) 
    must be done before calling this function.
    '''

    python = sys.executable
    os.execl(python, python, *sys.argv)


def handle_restart(e):
    e.page.window_destroy()

    # todo How to confirm that the application has exited?

    time.sleep(3)
    restart_program()


def main(page: ft.Page):
    btn = ft.ElevatedButton('restart', on_click=handle_restart)
    page.add(btn)


ft.app(target=main)

How to confirm that the application has exited after called page.window_destroy()?

@ndonkoHenri
Copy link
Collaborator

ndonkoHenri commented Apr 30, 2024

Calling destroy kills the application by closing the window.
Did your app window stay open?

@BrentHuang
Copy link
Author

BrentHuang commented Apr 30, 2024

Calling destroy kills the application by closing the window. Did your app window stay open?

If I use python ./demo.py to run the above code, I can restart it, but if I use flet run ./demo.py to run the above code, I cannot restart it. @ndonkoHenri

@BrentHuang
Copy link
Author

It would be great if there was a method called page.window_restart()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants