In this video I’ll show you how to use popup boxes for Kivy.
Pop Up boxes with Kivy are pretty easy, but a little different than other widgets. For one thing, they need
to be defined outside your main .kv widget.
We’ll also need to use something called Factory, which allows us to name and instantiate a Class from anywhere in our app.
Python Code: popup.py
GitHub Code: popup.py
from kivy.app import App from kivy.uix.widget import Widget from kivy.lang import Builder # Designate Our .kv design file Builder.load_file('popup.kv') class MyLayout(Widget): pass class AwesomeApp(App): def build(self): return MyLayout() if __name__ == '__main__': AwesomeApp().run()
Kivy Design Code: popup.kv
GitHub Code: popup.kv
#:import Factory kivy.factory.Factory <MyPopup@Popup> auto_dismiss: True size_hint: 0.6, 0.2 pos_hint: {"x":0.2, "top": 0.9} title: "This is a popup box" BoxLayout: orientation: "vertical" size: root.width, root.height Label: text: "Something in our popup box!" font_size: 24 Button: text: "Close Me!" font_size: 24 on_release: root.dismiss() <MyLayout> BoxLayout: orientation: "vertical" size: root.width, root.height Label: text: "Popup Stuff" font_size: 32 Button: text: "Popup" font_size: 32 on_release: Factory.MyPopup().open()
Add comment