[Python] Python Flet - AttributeError: 'str' object has no attribute '_set_attr_internal'

Discussão em 'Python' iniciado por Stack, Junho 23, 2025.

  1. Stack

    Stack Membro Participativo

    I tried to make a class to activate and deactivate admin mode (hide or not some element) to my flet app:

    class lock(ft.UserControl):
    def __init__(self,page:ft.Page):
    super().__init__()
    self.page =page

    def on_lock_click(self,e):
    self.page.dialog = self.dlg
    self.dlg.open = True
    self.page.update()

    def on_dlg_activate(self,e):
    if self.entry.value == "myPw":
    print('good')
    self.dlg.open = False
    else:
    print('bad')
    self.page.update()


    def build(self):
    self.entry = ft.TextField(label='Password')
    self.dlg = ft.AlertDialog(
    title = 'Admin',
    content = self.entry,
    actions = [
    ft.ElevatedButton(
    'log',
    on_click= self.on_dlg_activate
    )
    ]

    )
    return ft.IconButton(
    icon= ft.icons.LOCK,
    on_click= self.on_lock_click
    )


    As you can see, this class is composed of a button who is supposed to be called the AlerteDialog when clicked. But when I execute my code I got this error:

    Exception in thread Thread-4 (on_lock_click):
    Traceback (most recent call last):
    File "C:\...\Programs\Python\Python311\Lib\threading.py", line 1045, in _bootstrap_inner
    self.run()
    File "C:\...\Programs\Python\Python311\Lib\threading.py", line 982, in run
    self._target(*self._args, **self._kwargs)
    File ".\soft\src\widgets\lock.py", line 11, in on_lock_click
    self.page.update()
    File "C:\...\Local\Programs\Python\Python311\Lib\site-packages\flet_core\page.py", line 299, in update
    r = self.__update(self)
    ^^^^^^^^^^^^^^^^^^^
    File "C:\...\Local\Programs\Python\Python311\Lib\site-packages\flet_core\page.py", line 431, in __update
    commands, added_controls, removed_controls = self.__prepare_update(*controls)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\...\Local\Programs\Python\Python311\Lib\site-packages\flet_core\page.py", line 456, in __prepare_update
    control.build_update_commands(
    File "C:\...Local\Programs\Python\Python311\Lib\site-packages\flet_core\control.py", line 411, in build_update_commands
    ctrl.build_update_commands(
    File "C:\...\Local\Programs\Python\Python311\Lib\site-packages\flet_core\control.py", line 423, in build_update_commands
    innerCmds = ctrl._build_add_commands(
    ^^^^^^^^^^^^^^^^^^^^^^^^^
    children = self._get_children()
    ^^^^^^^^^^^^^^^^^^^^
    File "C:\...\Local\Programs\Python\Python311\Lib\site-packages\flet_core\alert_dialog.py", line 134, in _get_children
    self.__title._set_attr_internal("n", "title")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


    I read the flet documentations about AlertDialog: [text] (https://flet.dev/docs/controls/alertdialog) But I don't see the solution to my problem. Any idea?

    Continue reading...

Compartilhe esta Página