'Clock.schedule_once in kivy works as intended ONLY when runtime of previous function is short bug
.kv file
#:import Clock kivy.clock.Clock
#:import threading threading
#:import partial functools.partial
<MainScreen>:
BoxLayout:
size: root.size
orientation: "vertical"
BoxLayout:
Label:
id: wordcount
pos_hint: {'center_x':0.5,'y':0.6}
size_hint: 0.2,0.2
text: root.wordcount
Label:
pos_hint: {'center_x':0.5,'y':0.6}
size_hint: 0.2,0.2
id: BESTOPTIONS
text: root.entrophyvaluesbest
CustomBox:
id: layout
cols:5
Button:
pos_hint: {'center_x':0.5,'y':0.67}
size_hint: 0.5,0.1
text: "Click here to start!"
on_release: root.StartGame()
Button:
text: "Check your word!"
size_hint: 0.5,0.1
pos_hint:{'center_x':0.5,'y':0.4}
on_press:
a=threading.Thread(target=root.Check)
a.start()
a.join()
b=threading.Thread(target=root.ShowPreviousWord)
b.start()
b.join()
c=threading.Thread(target=root.ClearLetters)
c.start()
c.join()
d=threading.Thread(target=partial(Clock.schedule_once,root.FocusFirst,0.5))
d.start()
Label:
pos_hint:{'center_x':0.5,'y':-0.35}
id: OUTPUT
markup: True
My .py code is long, so I will try asking without that - My functions which occur while I click Button "Check your word" are sometimes taking to long - if the function a ( it is the only time consuming function there) takes too much time, then the Clock.schedule_once doesn't proc the FocusFirst function and because of that - nothing is focused then. I want to change the focus after all functions takes place - I know that main gui is in Main Thread, so it's not happening because of that, but I wonder if I am able to just make all functions happen first and then just change the focus and if so - how to do that.
I tried adding Clock.schedule_once without time argument, which makes it even worse.
I know that I can fix it by adding bigger time - for example 30 seconds, but I want the TextInput focus right after functions happen, not 30 seconds after that.
Solution 1:[1]
I resolved the issue and probably resolved the issue of GUI change block by some functions.
I simply took the function out of on_press and placed it to on_release, the button is being locked untill functions inside happen, then the button is released, so the function I wanted to postpone happens.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Micha? Mazur |
