Search code examples
pythonwidgetkivywindow

How do I make a widget fixed in Kivy? ( or a window)


I'm using kivy with Python 3.9

I have the window at 800x600

Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width',  800)
Config.set('graphics', 'height', 600)

This for some reason still allows me to later change window size, if there is a way to change that please help.

So I have a few buttons set up in a .kv file, and everything runs smoothly when I run it. The problem comes when I change the size of the window ( either by fullscreen or just messing with the window). When I do this the buttons start to change size randomly and just mess up. Is there a way to make the buttons adjust automaticcly with the size? Or to just make the stay a fixed size and not change at all? Thanks.

Update:

Kivy file

search : search
explore : explore


GridLayout:



    cols:1
    size: root.width -500, root.height -550
    pos: 250,350

    GridLayout:
        cols:1      



        TextInput:
            id: search
            multinline : False

    

        Button:
            text:"Search"

Python file

import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.core.window import Window
from kivy.config import Config 
from kivy.properties import ObjectProperty
import subprocess


Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width',  800)
Config.set('graphics', 'height', 600)






    
        

class MyGrid(Widget):
    explore = ObjectProperty(None)


    def btn_touch_up(self):        
        from subprocess import Popen, PIPE
        subprocess.Popen(['python',  'UI_1.py'])
        exit()


    

   
class MyApp(App): 
    def build(self):
        return MyGrid()

Solution

  • From the Config documentation:

    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.

    Just move the lines:

    from kivy.config import Config
    Config.set('graphics', 'resizable', False)
    Config.set('graphics', 'width',  800)
    Config.set('graphics', 'height', 600)
    

    to the very top of your py file.