Помогите исправить баг в 32 строке. SyntaxError: invalid syntax
Я знаю, что мой код полная ерунда нечитаемая, но помогите пожалуйста.
import flet as ft
def main(page: ft.Page):
page.theme_mode = 'dark'
page.window_width = 290
page.window_height = 335
page.window_resizable = False
page.title = 'Калькулятор'
def set_color_d(e):
page.theme_mode = 'dark'
page.update()
def set_color_l(e):
page.theme_mode = 'light'
page.update()
def main_(e):
page.add(calculator)
page.remove(settings)
h.disabled = True
s.disabled = False
page.update()
def settings_(e):
page.add(settings)
page.remove(calculator)
h.disabled = False
s.disabled = True
page.update()
prim = ft.TextField()
primer = str(prim.value)
def result(e):
res = eval(primer) #Баг здесь
print(res)
h = ft.MenuItemButton(
content=ft.Text("Home"),
leading=ft.Icon(ft.icons.HOME),
style=ft.ButtonStyle(bgcolor={ft.MaterialState.HOVERED: ft.colors.BLUE}),
on_click=main_,
disabled=False)
s = ft.MenuItemButton(
content=ft.Text("Settings")
leading=ft.Icon(ft.icons.SETTINGS),
style=ft.ButtonStyle(bgcolor={ft.MaterialState.HOVERED: ft.colors.BLUE}),
on_click=settings_,
disabled=False)
menubar = ft.MenuBar(
expand=True,
controls=[
ft.SubmenuButton(
content=ft.Text("Menu"),
controls=[
ft.Text('Mode'),
h,
s,
ft.Text('Theme'),
ft.MenuItemButton(
content=ft.Text("Dark"),
leading=ft.Icon(ft.icons.DARK_MODE),
style=ft.ButtonStyle(bgcolor={ft.MaterialState.HOVERED:
ft.colors.BLUE}),
on_click=set_color_d
),
ft.MenuItemButton(
content=ft.Text("Light"),
leading=ft.Icon(ft.icons.LIGHT_MODE),
style=ft.ButtonStyle(bgcolor={ft.MaterialState.HOVERED:
ft.colors.BLUE}),
on_click=set_color_l
)
]
),
])
menu = ft.Row([menubar])
page.add(menu)
calculator = ft.Column(
[
prim,
ft.Row(
[
ft.ElevatedButton('0'),
ft.ElevatedButton('1'),
ft.ElevatedButton('+'),
ft.ElevatedButton('/'),]),
ft.Row(
[
ft.ElevatedButton('2'),
ft.ElevatedButton('3'),
ft.ElevatedButton('4'),
ft.ElevatedButton('x'),]),
ft.Row(
[
ft.ElevatedButton('5'),
ft.ElevatedButton('6'),
ft.ElevatedButton('7'),
ft.ElevatedButton('-'),]),
ft.Row(
[
ft.ElevatedButton('8'),
ft.ElevatedButton('9'),
ft.ElevatedButton(','),
ft.ElevatedButton('=', bgcolor=ft.colors.BLUE, color=ft.colors.WHITE, on_click=result)])
]
)
settings = ft.Column(
[
ft.Text('Settings', size=28)
]
)
page.add(calculator)
ft.app(target=main, view=ft.AppView.FLET_APP)