Search code examples
pythonmacoskivykivy-language

Trying to Run Kivy Application on MacOS, but getting black screen when run


I have been trying to run my kivy application on my Mac, however when I run it all I get is a black screen. I have tried doing everything that I can, however I simply cannot get it to work. I have also tried manually loading the kv file, but that also did not work.

Here is my Python Code:

import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
import random


kivy.require('2.0.0') 

class MyRoot(BoxLayout):
    def __init__(self):
        super().__init__()

    def generate_number(self):
        self.random_label.text = str(random.randint(0, 1000))

class Test(App):

    def build(self):
        return MyRoot()

Test = Test()
Test.run()

Here is my KV File:

<MyRoot>:

    random_label: random_label
    
    BoxLayout:
        orientation: 'vertical'
        Label:
            text: 'Random'
            font_size: 64
            color: 0.92, 0.45, 0
        Label:
            id: random_label
            text: '-'
            font_size: 64

        Button:
            text: 'Generate'
            font_size: 32
            size: 100, 50
            on_press: root.generate_number()

Solution

  • I found out that the issue was with the python version I ran it with Python 3.10 instead of 3.9 and now it worked.