Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. Kivy provides you the functionality to write the code for once and run it on different platforms. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications.
Kivy is that platform where the size does not matter a lot as it is self-adjusting accordingly but What if we want to fix the size to some extent whether its hight wise or width wise or free from boundation depends on the user requirement.
In this article, we are going to see three formats of resizing the window size in kivy.
Note: Just note the size in the outputs of the window and check the minimize and maximize button on window when it is visible or when not visible.
For resizing window we have:
from kivy.config import Config
Kivy has a configuration file which determines the default settings. In order to change these settings, you can alter this file manually or use the Config object.
Configuration options control the initialization of the App. In order to avoid situations where the config settings do not work or are not applied before window creation (like setting an initial window size), Config.set should be used before importing any other Kivy modules. Ideally, this means setting them right at the start of your main.py script.
When there is no fix window size i.e fully resizable according to user:
# To change the kivy default settings# we use this module configfrom kivy.config import Config # 0 being off 1 being on as in true / false# you can use 0 or 1 && True or FalseConfig.set('graphics', 'resizable', True) # import kivy moduleimport kivy # this restrict the kivy version i.e# below this kivy version you cannot use the appkivy.require("1.9.1") # base Class of your App inherits from the App class.# app:always refers to the instance of your applicationfrom kivy.app import App # if you not import label and use it through errorfrom kivy.uix.label import Label # defining the App classclass MyLabelApp(App): def build(self): # label display the text on screen # markup text with different colour l2 = Label(text ="[color = ff3333][b]Hello !!!!!!!!!!![/b] [/color]\n [color = 3333ff]GFG !!:):):):)[/color]", font_size ='20sp', markup = True) return l2 # creating the objectlabel = MyLabelApp() # run the windowlabel.run() |
Output:
No resizing, fixed size with the width:
# To change the kivy default settings# we use this module configfrom kivy.config import Config # 0 being off 1 being on as in true / false# you can use 0 or 1 && True or FalseConfig.set('graphics', 'resizable', '0') # fix the width of the window Config.set('graphics', 'width', '500') |
Output:
Fix the hight of the window:
# to change the kivy default settings# we use this module configfrom kivy.config import Config # 0 being off 1 being on as in true / false# you can use 0 or 1 && True or FalseConfig.set('graphics', 'resizable', '0') # fix the height of the window Config.set('graphics', 'height', '400') |
Output:
We can use both height and width restriction together:
# to change the kivy default settings# we use this module configfrom kivy.config import Config # 0 being off 1 being on as in true / false# you can use 0 or 1 && True or FalseConfig.set('graphics', 'resizable', '0') # fix the width of the window Config.set('graphics', 'width', '500') # fix the height of the window Config.set('graphics', 'height', '500') |
Output:
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


