Popup¶
New in version 1.0.7.

The Popup widget is used to create modal popups. By default, the popup will cover the whole “parent” window. When you are creating a Popup, you must at minimum set a Popup.title and a Popup.content widget.
Remember that the default size of a Widget is size_hint=(1, 1). If you don’t want your popup to be fullscreen, deactivate the size_hint and use a specific size attribute.
Examples¶
Example of a simple 400x400 Hello world popup:
popup = Popup(title='Test popup',
content=Label(text='Hello world'),
size_hint=(None, None), size=(400, 400))
By default, any click outside the popup will dismiss it. If you don’t want that, you can set Popup.auto_dismiss to False:
popup = Popup(title='Test popup', content=Label(text='Hello world'),
auto_dismiss=False)
popup.open()
To manually dismiss/close the popup, use Popup.dismiss():
popup.dismiss()
The Popup.open() and Popup.dismiss() are bindable. That means you can directly bind the function to an action, like an a Button’s on_press
# create content and assign to the popup
content = Button(text='Close me!')
popup = Popup(content=content, auto_dismiss=False)
# bind the on_press event of the button to the our dismiss function
content.bind(on_press=popup.dismiss)
# open the popup
popup.open()
Popup events¶
There are 2 events available: on_open when the popup is opening, and on_dismiss when it is closed. For on_dismiss, you can prevent the popup from closing by explictly returning True from your callback
def my_callback(instance):
print 'Popup', instance, 'is beeing dismiss, but i dont want!'
return True
popup = Popup(content=Label(text='Hello world'))
popup.bind(on_dismiss=my_callback)
popup.open()
- class kivy.uix.popup.Popup(**kwargs)¶
Bases: kivy.uix.floatlayout.FloatLayout
Popup class, see module documentation for more information.
Events : - on_open:
Fired when the Popup is opened
- on_dismiss:
Fired when the Popup is closed. If the callback returns True, the dismiss will be canceled.
- attach_to¶
If a widget is set on attach_to, the popup will attach to the nearest parent window of the Widget. If none is found, it will attach to the main/global Window.
attach_to is a ObjectProperty, default to None.
- auto_dismiss¶
Default to True, this property determines if the popup is automatically dismissed when the user clicks outside it.
auto_dismiss is a BooleanProperty, default to True.
- background¶
Background image of the popup used for the popup background.
New in version 1.1.0.
background is an StringProperty, default to ‘atlas://data/images/defaulttheme/popup-background’
- background_color¶
Background color, in the format (r, g, b, a).
New in version 1.1.0.
background_color is a ListProperty, default to [0, 0, 0, .7].
- border¶
Border used for BorderImage graphics instruction, used itself for background_normal and background_down. Can be used when using custom background.
New in version 1.1.0.
It must be a list of 4 value: (top, right, bottom, left). Read the BorderImage instruction for more information about how to play with it.
border is a ListProperty, default to (16, 16, 16, 16)
- content¶
Content of the popup, that is displayed just under the title.
content is a ObjectProperty, default to None.
- dismiss(*largs, **kwargs)¶
Close the popup if it’s opened. If you really want to close the popup, whatever the on_dismiss event return, you can do like this:
popup = Popup(...) popup.dismiss(force=True)
Changed in version 1.3.0.
- open(*largs)¶
Show the popup window from the attach_to widget. If set, it will attach to the nearest window. If the widget is not attached to any window, the popup will attach to the global Window.
- separator_color¶
Color used by the separator between title and content.
New in version 1.1.0.
background_color is a ListProperty, default to [47 / 255., 167 / 255., 212 / 255., 1.]
- separator_height¶
Height of the separator.
New in version 1.1.0.
separator_height is a NumericProperty, default to 2.
- title¶
String that represent the title of the popup.
title is a StringProperty, default to ‘No title’.