我正在用 Kivy 编写程序,每当我尝试将函数绑定到 Button 或任何其他小部件时,我都会从 pylint 中得到以下问题:“'Button' 实例没有 'bind' 成员”和线变红。我对 Kivy 完全陌生,这让我很烦恼。
该程序在我执行时运行良好,编译器似乎对我的绑定没有任何问题。我做错了什么?我是否缺少导入或任何东西,或者我的环境有问题?
附上我写的一个代码片段作为例子。
from kivy.app import App
from kivy.uix.button import Button
class MainApp(App):
def build(self):
button = Button(text='Hello from Kivy',
size_hint=(.5, .5),
pos_hint={'center_x': .5, 'center_y': .5})
button.bind(on_press=self.on_press_button)
return button
def on_press_button(self, instance):
print('You pressed the button!')
if __name__ == '__main__':
app = MainApp()
app.run()
答案 0 :(得分:0)
很可能您使用的任何 linter 都无法找到 bind 方法,因为它来自 cython 代码。您需要对其进行不同的配置(如果可能),或者使用不同的 linter。