Python | Popup widget in Kivy
Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.
Popup widget :
- The Popup widget is used to create popups. By default, the popup will cover the whole “parent” window. When you are creating a popup, you must at least set a Popup.title and Popup.content.
- Popup dialogs are used ]when we have to convey certain obvious messages to the user. Messages to the user through status bars as well for specific messages which need to be told with emphasis can still be done through popup dialogs.
- Keep one thing in mind that the default size of a widget is size_hint=(1, 1).
- If you don’t want your popup to be on the full screen you must gave either size hints with values less than 1 (for instance size_hint=(.8, .8)) or deactivate the size_hint and use fixed size attributes.
To use popup you must have to import :
from kivy.uix.popup import Popup
Note: Popup is a special widget. Don’t try to add it as a child to any other widget. If you do, Popup will be handled like an ordinary widget and won’t be created hidden in the background.
Basic Approach : 1) import kivy 2) import kivyApp 3) import Label 4) import button 5) import Gridlayout 6) import popup 7) Set minimum version(optional) 8) create App class 9) return Layout/widget/Class(according to requirement) 10) In the App class create the popup 11) Run an instance of the class
When click on screen popup will open like this:
When click on Close the popup it will close.
In the second code when we use the size_hint and the size we can give the size accordingly. In this just add something as in the below code in line number 75.
Popup size will be smaller than the window size.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course