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()

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder