I am using kivy for an application in python and I think I configured the installation of kivy incorrectly. I'm trying to use a KV file and reference a root class. Since the Builder loads the file, there is no class for the KV file to reference and I get a "'FloatLayout' has no attribute 'test'" error. But if I create a class in the KV file, and then return the reference class, it will not display the button. If I try and reference the method placed in Tracker(app) class, that does nothing. What do I need to change with either my configuration or my code to fix my issue?
This problem persists in the app I'm working on and also this test-code below.
IDE is Visual Studios if that matters
(.py file)
import kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.lang import Builder
class One(FloatLayout):
def test(self):
print("Clicked")
class Main(App):
def build(self):
print("Running")
#return One()
return Builder.load_file("one.kv")
if __name__ == '__main__':
Main().run()
(KV file)
#<One>:
FloatLayout:
Button:
text: "Enter"
size_hint: None, None
size: 100, 50
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
on_press: root.test()
I want to be able to click the button and "Clicked" be printed.
Just change
FloatLayout
in yourkv
file toOne
: