abeldattsun
abeldattsun

Reputation: 61

Kivy Invalid data after declaration on_press

I'm trying to add 2 buttons to my Kivy applications with a floatlayout and have an on_press call. When I try to run this I just get an error: Invalid data after declaration on line 12

my main.py

import kivy

from kivy.app import App
from kivy.uix.widget import Widget 
import __init__ as hvn


class HVNLayout(Widget): 
    def optBtn(self):
       print("hello") 

    def genBtn(self):
        print("Bye")
  
class HVNApp(App):
    def build(self):
        return HVNLayout() 


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

and the .kv

<HVNLayout>:
    canvas.before:
        Rectangle:
            size: self.size
            source: "images/dice.jpg"

    FloatLayout:
        size: root.width, root.height

        Button:
            text: "Option"
            on_press: root.btn()
            pos_hint: {"top": 1, "right": 1}
            size_hint: (None, None)
            size: 200, 100

        Button:
            text: "Generate"
            post_hint: {"x": 0.15, "y": 0.1}
            size_hint: (None, None)
            size: 200, 100

Upvotes: 0

Views: 80

Answers (1)

jda5
jda5

Reputation: 1446

The indentation of your kv file is incorrect. It should be:

<HVNLayout>:
    canvas.before:
        Rectangle:
            size: self.size
            source: "images/dice.jpg"

    FloatLayout:
        size: root.width, root.height

        Button:
            text: "Option"
            on_press: root.btn()
            pos_hint: {"top": 1, "right": 1}
            size_hint: (None, None)
            size: 200, 100

    Button:
        text: "Generate"
        post_hint: {"x": 0.15, "y": 0.1}
        size_hint: (None, None)
        size: 200, 100

Upvotes: 1

Related Questions