i am trying to create an app that merges one or more pdf files in python using flet, my code below shows an empty banner display text when i run the code, i tested the two if statement inside the merge_pdfs function but it always display an empty status_banner
status_banner = ''
def main(page: ft.page):
def close_banner(e):
page.banner.open = False
page.update()
def show_banner(e):
page.banner.open = True
page.update()
def merge_pdfs(e: ft.FilePickerResultEvent):
# get file name and password from the corresponding textfields
merge_file_name = textField_name.value
file_password = textField_password1.value
# show warning when no filename is provided
if not merge_file_name or merge_file_name == ' ':
status_banner = "Please check the file name entered."
show_banner(e)
return None
# show warning if less than 2 files selected
if not e.files or len(e.files) < 2:
status_banner = "Please select at least 2 files."
show_banner(e)
return None
pick_files_dialog = ft.FilePicker(on_result=merge_pdfs)
page.overlay.append(pick_files_dialog)
...
# banner for when there is error in file name or file selection
page.banner = ft.Banner(
bgcolor=ft.colors.RED_500,
leading=ft.Icon(ft.icons.WARNING_AMBER_ROUNDED,
color=ft.colors.AMBER, size=40),
content=ft.Text(status_banner),
actions=[ft.TextButton("Dismiss", on_click=close_banner)])
a workaround solution, putting the banner inside the 2 if statements, if anyone has a better solution im open to it.
update 2 using a class