在我的树莓派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'
from pyforms.gui.standaloneManager import start_app
。请检查您的PYFORMS_MODE环境变量:在start_app
之前执行以下操作:import os; print(os.environ.get('PYFORMS_MODE'))
。 - 9dogsPYFORMS_MODE
环境变量未设置,因此我尝试将其设置为GUI
,但结果相同。 - Error404pyforms.gui.standaloneManager
导入start_app
时出现了ImportError
(请参见更新的问题)。 - Error404