Change label.text but no Update
Hi,
i am changing the "label1.text" with this function, but on my view it is not updated? Can you tell me how to activate an update of the view?
Thanks a lot.
BR kami
` def swswitch (sender): if main['connectsw'].value == True:
main['label1'].text = " Waiting..."
#main.update()
cb.scan_for_peripherals()
count = time.time()
while not mngr.peripheral and count >= time.time()-10:
pass
if mngr.peripheral == None:
main['label1'].text = " Device not found..."
main['connectsw'].value = False
cb.stop_scan()
else:
#v['viewbottom']['label1'].text = " Disconnected..."
if mngr.peripheral != None:
cb.cancel_peripheral_connection(mngr.peripheral)
pass
`
Try
from objc_util import main_thread
@main_thread
def swswitch (sender):
Hi thanks but main_thread is Not defined. BR kami
Sorry, my error
from objc_util import *
@on_main_thread
No Problem but now it is defined but no Update. 🫤
Last try, instead of previous bad advice
@ui.in_background
def swswitch (sender):
Same Problem
weird, sure that your code is executed, as it is in an "if", perhaps your could print something to confirm
If you agree for a test more 🙄
@on_main_thread
def update_label(text):
main['label1'].text = text
@ui.in_background
def swswitch (sender):
if main['connectsw'].value == True:
update_label("" Waiting...")
...
Hi test failed 🫤
I can't help more, sorry, you have to be sure that your code is executed. Put a print in the update_label def.
The Print command in def update_Label is executed but now the Label.text also with "device not found" is not updating. This works before.
Sorry for you, hoping a Pythonista guru will help you. Do you use the beta version or the App Store version?
It is normal that your original code was only displaying the last text of the label because your def is entirely executed before the label could be updated.
Okay but thanks a lot for your help. I am using the Beta.
Perhaps is the beta the origin of the problem...