Python 从快速 GUI 编程错误中查找并替换对话框
Python find and replace dialog from Rapid GUI Programming error
从 "Rapid GUI Programming with Python and Qt (Chapter 07), by Prentice Hall (Mark Sumerfield)" 构建查找和替换对话框时,出现以下错误:
import ui_findandreplacedlg
ImportError: No module named ui_findandreplacedlg
根据python我运行的哪个版本,我还得到:
File "findandreplacedlg.py", line 7, in <module>
ui_findandreplacedlg.Ui_FindAndReplaceDlg):
AttributeError: 'module' object has no attribute 'Ui_FindAndReplaceDlg'
我从他们的网站上获得了源代码,它以同样的方式在同一行出错。我在他们的网页上搜索了勘误表,但没有任何提及。有谁知道解决方案是什么?
相关代码可在此处找到 - https://github.com/suzp1984/pyqt5-book-code/blob/master/chap07/ui_findandreplacedlg.py。如果该文件与您尝试 运行 的代码位于同一目录中,只需执行
import ui_findandreplacedlg
您需要使用 pyuic
工具转换 ui
文件。这在书中解释如下(第 206 页):
Once a user interface has been designed and saved in a .ui file, it
must be con- verted into code before it can be used. This is done
using the pyuic4 command- line program. For example:
C:\pyqt\chap07>pyuic4 -o ui_findandreplacedlg.py findandreplacedlg.ui
或者如果您在 Linux:
$ cd pyqt/chap07
$ pyuic4 -o ui_findandreplacedlg.py findandreplacedlg.ui
$ python findandreplacedlg.py
从 "Rapid GUI Programming with Python and Qt (Chapter 07), by Prentice Hall (Mark Sumerfield)" 构建查找和替换对话框时,出现以下错误:
import ui_findandreplacedlg
ImportError: No module named ui_findandreplacedlg
根据python我运行的哪个版本,我还得到:
File "findandreplacedlg.py", line 7, in <module>
ui_findandreplacedlg.Ui_FindAndReplaceDlg):
AttributeError: 'module' object has no attribute 'Ui_FindAndReplaceDlg'
我从他们的网站上获得了源代码,它以同样的方式在同一行出错。我在他们的网页上搜索了勘误表,但没有任何提及。有谁知道解决方案是什么?
相关代码可在此处找到 - https://github.com/suzp1984/pyqt5-book-code/blob/master/chap07/ui_findandreplacedlg.py。如果该文件与您尝试 运行 的代码位于同一目录中,只需执行
import ui_findandreplacedlg
您需要使用 pyuic
工具转换 ui
文件。这在书中解释如下(第 206 页):
Once a user interface has been designed and saved in a .ui file, it must be con- verted into code before it can be used. This is done using the pyuic4 command- line program. For example:
C:\pyqt\chap07>pyuic4 -o ui_findandreplacedlg.py findandreplacedlg.ui
或者如果您在 Linux:
$ cd pyqt/chap07
$ pyuic4 -o ui_findandreplacedlg.py findandreplacedlg.ui
$ python findandreplacedlg.py