Reputation: 71
I need to dismiss the pop up after finishing a function in another class, or at least after specific time like (3 second) the pop up displaying loading gif image to notify the user to wait for operating the functions
*******python******
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
class ScreenManagement(ScreenManager):
pass
class progress(Popup):
pass
class Func_(Screen):
# function
pass
presentation = Builder.load_file("Try_.kv")
class MainApp(App):
def build(self):
return presentation
if __name__ == "__main__":
MainApp().run()
********KV File*********
#:import Factory kivy.factory.Factory
<Popup>:
separator_color: 1, 1, 1, 1
background: "White.png"
Button:
id: btn
disabled: True
background_disabled_normal: "White.png"
text: "Hello"
Image:
source: "Loading.gif"
size: root.size
ScreenManagement:
PopupBox:
<PopupBox>:
BoxLayout:
Button:
text: "Click"
on_release:
Factory.Popup().open()
Upvotes: 2
Views: 3669
Reputation: 16041
You have to add a function to dismiss the Popup message and use Clock.schedule_once to call that function. Please refer to the example below for details.
from kivy.app import App
from kivy.uix.popup import Popup
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.clock import Clock
class ScreenManagement(ScreenManager):
pass
class Progress(Popup):
def __init__(self, **kwargs):
super(Progress, self).__init__(**kwargs)
# call dismiss_popup in 2 seconds
Clock.schedule_once(self.dismiss_popup, 2)
def dismiss_popup(self, dt):
self.dismiss()
class Func(Screen):
# function
pass
class MainApp(App):
def build(self):
return ScreenManagement()
if __name__ == "__main__":
MainApp().run()
#:import Factory kivy.factory.Factory
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
<Progress>:
separator_color: 1, 1, 1, 1
background: "White.png"
Button:
id: btn
disabled: True
background_disabled_normal: "White.png"
text: "Hello"
Image:
source: "Loading.gif"
size: root.size
<ScreenManagement>:
transition: FadeTransition()
Func:
<Func>:
BoxLayout:
Button:
text: "Click"
on_release:
Factory.Progress().open()
Upvotes: 2