Nisarg
Nisarg

Reputation: 473

Breaking Main loop in kivy (Freezing Screen)

I got and issue that when i bind a function with an button that works good but when i bind a function which has a infinite loop in it so screen freezes and other button do not works as example below....please give me solution to break that loop using another button..

from kivy.uix.popup import Popup
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.label import Label
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.stacklayout import StackLayout

class APPLICATION_START(FloatLayout):
    def __init__(self, **kwargs):
        super(MyApp, self).__init__(**kwargs)
        self.buone = Button(text="Start Loop",pos=(0,180),size=(470,90),size_hint=(None,None))
        self.logi.bind(on_release=self.loooop)
        self.exitbtn = Button(text="exit",pos=(0,90),size=(235,70),size_hint=(None,None))
        self.exitbtn.bind(on_press=exit)

    def loooop(self,instance):
        while True:
            # do any Activity

        #I want to break this loop when someone press on exit button

class MyApp(App):
    def build(self):
        return APPLICATION_START()

if __name__ == '__main__':
    MyApp().run()

Upvotes: 0

Views: 2018

Answers (1)

inclement
inclement

Reputation: 29450

The gui can't update until your function returns, which it doesn't.

Either use a thread for your task, or if it is composed of many repetitions of a short task you can do Clock.schedule_interval(your_function, some_timestep) to run it repeatedly.

Upvotes: 1

Related Questions