在我的Raspberry Pi 3上安装pyforms后,我尝试运行readthedocs上找到的示例,但应用程序正在抛出AttributeError
(我试过python2和python3)
Python代码
import pyforms
from pyforms import BaseWidget
from pyforms.Controls import ControlText
from pyforms.Controls import ControlButton
class SimpleExample1(BaseWidget):
def __init__(self):
super(SimpleExample1,self).__init__('Simple example 1')
#Definition of the forms fields
self._firstname = ControlText('First name', 'Default value')
self._middlename = ControlText('Middle name')
self._lastname = ControlText('Lastname name')
self._fullname = ControlText('Full name')
self._button = ControlButton('Press this button')
#Execute the application
if __name__ == "__main__": pyforms.start_app( SimpleExample1 )
错误:
Traceback (most recent call last):
File "PiControl.py", line 20, in <module>
if __name__ == "__main__": pyforms.start_app( SimpleExample1 )
AttributeError: ‘module’ object has no attribute ‘start_app’
修改
我尝试使用
手动导入start_app
from pyforms.gui.standaloneManager import start_app
然后我得到另一个ImportError
:
Traceback (most recent call last):
File "PiControl.py", line 4, in <module>
from pyforms.gui.standaloneManager import start_app
ImportError: cannot import name 'start_app'
答案 0 :(得分:3)
这是非常奇怪的行为,可能意味着您的安装已损坏。尝试从repo安装最新版本:
pip install -U git+https://github.com/UmSenhorQualquer/pyforms.git
pip install -U git+https://github.com/UmSenhorQualquer/pysettings.git
pip install -U git+https://bitbucket.org/fchampalimaud/logging-bootstrap.git
答案 1 :(得分:-1)
在阅读pyforms的github网站后,我了解到它是一个Web框架。 所以我认为它会像其他Web框架一样。并且错误说'module'没有'start_app'方法,所以我认为你可能没有声明app instance.'start_app'应该由web app实例拥有。 可能是错的,因为我没有阅读文档。