Kivy — it is a platform independent GUI tool in Python. Since it can run on Android, IOS, Linux, Windows, etc. It is mainly used to develop Android application, but that does not mean that it cannot be used in desktop applications.
Toggle Button:
The ToggleButton widget acts like a checkbox. When you touch or click on it, the state toggles between "normal" and "down" (as opposed to a button that is only "down" while pressed).
Toggle buttons can also be grouped to create switches — only one button in a group can be in the down state. The group name can be a string or any other Python hashable object:
btn1 = ToggleButton (text = ’Male’, group =’ sex’,) btn2 = ToggleButton (text = ’Female’, group =’ sex ’, state =’ down’) btn3 = ToggleButton (text = ’Mixed’, group =’ sex’)
Only one of the buttons can be pressed / disabled at the same time. You can use the same properties to customize the ToggleButton as for the Button class.
Basic Approach: 1) import kivy 2) import kivyApp 3) import toggle button 4) import Gridlayout 5) Set minimum version (optional) 6) create layout class 7) create App class 8) create the, kv file 9) return Layout / widget / Class (according to requirement) 10) Run an instance of the class
Implementation of the approach:
.py code:
|
Code .kv :
< code class = "undefined spaces">
|
Output: