【发布时间】:2021-03-29 01:58:15
【问题描述】:
我正在尝试使用浮动布局向我的 Kivy 应用程序添加 2 个按钮并进行 on_press 调用。当我尝试运行它时,我收到一个错误:第 12 行声明后数据无效
我的 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()
和.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
【问题讨论】:
标签: python kivy kivy-language