question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make uix widgets accessible with "from kivy.uix import Button..."

See original GitHub issue

It seems almost trivial, but would it be possible to make some of the more commonly used/base widgets accessible in the kivy/uix/__init__.py module?

This would mean instead of needing to do the following:

from kivy.uix.button import Button
from kivy.uix.label import Label
...
from kivy.uix.scatter import Scatter

You only need to do the following:

from kivy.uix import Label, Button, ... , Scatter

The reason for this request is mainly to help tidy up the imports a little and means it isn’t necessary to write a 30 almost identical lines when wanting to import 30 different widgets.

As far as I can tell, you would just need to import the desired classes into the kivy/uix/__init__.py module and adjust the __all__ variable like so:

# kivy/uix/__init__.py

from kivy.uix.button import Button
from kivy.uix.label import Label
...
from kivy.uix.scatter import Scatter

__all__ = ['Button', 'Label', ..., 'Scatter']

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
ghostcommented, Apr 25, 2016

Worth mentioning that Factory provides easy import if you need it;

from kivy.factory import Factory

lbl = Factory.Label(text="Hello World")

class MyScatter(Factory.Scatter):
    pass
0reactions
inclementcommented, Apr 25, 2016

I’m referring to the reason not to have this type of import - if all the widgets are imported by __init__.py it imposes a minor perfomance penalty whenever you import any widget, since all of their files are loaded. This penalty would be quite small though, I don’t know if it’s important (though on Android these things can be relevant even if negligible on the desktop).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Widgets — Kivy 2.1.0 documentation
A Widget is the base building block of GUI interfaces in Kivy. It provides a Canvas that can be used to draw on...
Read more >
Kivy: Get widgets ids and accessing widgets by unique property
The id works like a python dict key id:Widget but only if ... from kivy.uix.label import Label from kivy.uix.button import Button kv ...
Read more >
Python | Layouts in layouts (Multiple Layouts) in Kivy
Basic Approach to create multiple layouts in one file: 1) import ... from kivy.uix.button import Button ... It takes the available space and....
Read more >
List - KivyMD 1.1.1 documentation
from kivy.lang import Builder from kivymd.app import MDApp from ... from kivy.uix.button import Button >>> root = Widget() >>> button = Button() > ......
Read more >
Kivy Menagerie. A reference collection of Kivy widgets…
from kivy.uix.button import Button from kivy.uix.slider import Sliderclass manyWidgetsApp(App): def build(self): layout = GridLayout(cols=2)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found