Chapter 8. Advanced Widgets
Your weather app is now fully functional and you could do an initial release already. However, there are a few things you can do to make it better. This chapter is a large code refactor. The functionality won’t change very much, but the usability will improve and the amount of code involved will shrink, which means fewer bugs and easier maintenance.
Kivy has an abundant collection of built-in widgets, and this book can’t cover all of them. In this chapter, you’ll see three of them in detail: the Carousel
, ModalView
, and ActionBar
. These widgets will largely replace much of the screen management code you have written manually so far.
Be prepared. This will be a large refactor, and you will probably have to do quite a bit of debugging to get everything working correctly. This is great real-world practice, though, as reworking existing code is an important part of the software development process. Applications that don’t evolve over time are inevitably superceded.
Before you start, remove your brand new gesture_box.py file altogether and revert the two classes in main.py to extend BoxLayout
instead of GestureBox
. You’ll also need to remove an import
statement.
Also remove the custom gesture event listeners (such as on_right_to_left_line
) from the KV language file.
If your refactor begins with removing entire files of custom code that you no longer have to maintain, you’re probably doing something right!
Carousel
The Carousel
widget allows for swiping between multiple ...
Get Creating Apps in Kivy now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.