I want to create a simple stopwatch in Python using the Flet, how can I get my value out of the while loop?
<code>import flet as ft
from time import sleep
def stopwatch():
time = 0
str_time = ''
while True:
time += 1
str_time = str(time)
print(str_time, time) #for check work or not
sleep(1)
def main(page: ft.Page):
t = ft.Text(value=stopwatch(), color='red') #no value is transmitted
page.controls.append(t)
page.update()
ft.app(target=main)
</code>
<code>import flet as ft
from time import sleep
def stopwatch():
time = 0
str_time = ''
while True:
time += 1
str_time = str(time)
print(str_time, time) #for check work or not
sleep(1)
def main(page: ft.Page):
t = ft.Text(value=stopwatch(), color='red') #no value is transmitted
page.controls.append(t)
page.update()
ft.app(target=main)
</code>
import flet as ft
from time import sleep
def stopwatch():
time = 0
str_time = ''
while True:
time += 1
str_time = str(time)
print(str_time, time) #for check work or not
sleep(1)
def main(page: ft.Page):
t = ft.Text(value=stopwatch(), color='red') #no value is transmitted
page.controls.append(t)
page.update()
ft.app(target=main)
I tried to use return and the value 1 was passed, but the while loop stopped there.
Possibly I don’t know much Python and especially the Flet, but I managed to write such a simple program using TKinter, I want to repeat the same success with Flet)
New contributor
Pro Bany is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.