![](/img/trans.png)
[英]What is this code from createEditor actually doing (Rapid Gui Programming With Python and Qt)
[英]Python find and replace dialog from Rapid GUI Programming error
当从“使用Python和Qt进行快速GUI编程(第07章),由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页):
一旦设计了用户界面并将其保存在.ui文件中,就必须先将其转换为代码才能使用它。 这是使用pyuic4命令行程序完成的。 例如:
C:\\pyqt\\chap07>pyuic4 -o ui_findandreplacedlg.py findandreplacedlg.ui
或者如果你在Linux上:
$ cd pyqt/chap07
$ pyuic4 -o ui_findandreplacedlg.py findandreplacedlg.ui
$ python findandreplacedlg.py
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.