Kivy - Inspector



Kivy provides a very useful tool called Inspector, which helps you in rectifying the problems encountered when implementing the interface designed with the "kv" script or programmatically. The Inspector tool has a command-line interface, and it can also be used from within the code.

The command-line usage is −

python main.py -m inspector

To use it programmatically, call the create_inspector() function in the "kivy.modules.inspector" module.

from kivy.modules import inspector

class Demo(App):
   def build(self):
      button = Button(text="Test")
      inspector.create_inspector(Window, button)
      return button

Obviously, the command-line usage is more convenient. Let us find out the utility of this tool.

Assume that you have developed a Kivy application with slider.py program that has the following interface.

Kivy Inspector

The app has three slider controls that help in changing the color of the text above.

Start the program from the command prompt with the following command −

python sliderdemo.py -m inspector

The above screen will be displayed. Press ctrl+E keys to display the Inspector bar.

Kivy Inspect Bar

The bar can be moved to top or bottom for convenience. Click on any of the components on the window. The wide button displays the Object ID of the clicked widget. Now press the Parent button. The Parent widget of the select widget will be highlighted.

Kivy Inspector Highlight

Double click on the wide button. It will now show three panes with splitters to adjust the sizes. The left pane shows the widget tree, the middle pane shows all the properties of the selected widget and the one on the right shows the value of selected property.

The following figure shows that the BLUE slider is selected from the widget tree, its properties are displayed in the middle pane, and the max property value is seen in the right pane.

Kivy Inspector Right Pane

You can also change the property value from the inspector tool. Scroll down the middle pane to locate the value property and change its value in the right pane text box.

Kivy Inspector Text Box

The Inspector tool can be very useful in troubleshooting the user interfaces.

Advertisements