【发布时间】:2014-09-14 22:02:58
【问题描述】:
我在为 on_press 事件运行一段代码时遇到问题,这是我的代码:
MAIN.py
#!/usr/bin/python3.4
import kivy
kivy.require('1.0.7')
from kivy.app import App
from kivy.uix.button import Button
class helloworldApp(App):
def action(self):
print('Hi')
app=helloworldApp()
app.run()
helloworld.kv
BoxLayout:
orientation:'vertical'
Button:
text: "Hello world"
id: btn1
on_press: action()
Button:
text: "Hello world"
Button:
text: "Hello world"
Button:
text: "Love you world"
当我运行它时,一切看起来都很好,但是当我按下第一个按钮时,我得到了
文件“/home/user/Kivy/helloworld.kv”,第 6 行,在 on_press:动作() NameError: name 'action' is not defined
我尝试使用root.action() 和self.action(),但没有成功
【问题讨论】:
标签: python user-interface kivy