Search code examples
pythonkivyframe-rate

Setting maxfps using Config in Python's Kivy doesn't limit the fps


I want to define a limit for fps in Kivy.

I tried to limit fps to 60 with Config.set('graphics', 'maxfps', '60') but I was still getting around 70 to 80 fps at least according to Clock.schedule_interval(lambda dt: print(Clock.get_fps()), 1).

Here's my full code:

from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.config import Config

Config.set('graphics', 'maxfps', '60')


class SimpleKivy(App):
    def build(self):
        Clock.schedule_interval(lambda dt: print(Clock.get_fps()), 1)
        return Label(text='Hello world!')


if __name__ == '__main__':
    SimpleKivy().run()

Solution

  • The import order is important here. The example works when importing the config before importing anything else kivy related:

    from kivy.config import Config
    
    Config.set('graphics', 'maxfps', '10')
    
    from kivy.app import App
    from kivy.clock import Clock
    from kivy.uix.label import Label
    
    
    
    class SimpleKivy(App):
        def build(self):
            Clock.schedule_interval(lambda dt: print(Clock.get_fps()), 1)
            return Label(text='Hello world!')
    
    
    if __name__ == '__main__':
        SimpleKivy().run()
    

    As mentioned in the related github issue on the Kivy bugtracker, FPS might over/undershoot slightly but it's a general direction.