简体   繁体   English

Python从Rapid GUI Programming错误中查找并替换对话框

[英]Python find and replace dialog from Rapid GUI Programming error

When building the find and replace dialog from "Rapid GUI Programming with Python and Qt (Chapter 07), by Prentice Hall (Mark Sumerfield)", I get the following error: 当从“使用Python和Qt进行快速GUI编程(第07章),由Prentice Hall(Mark Sumerfield)”构建查找和替换对话框时,我收到以下错误:

    import ui_findandreplacedlg
ImportError: No module named ui_findandreplacedlg

Depending on which version of python I run, I also get: 根据我运行的python版本,我还得到:

File "findandreplacedlg.py", line 7, in <module>  
    ui_findandreplacedlg.Ui_FindAndReplaceDlg):  
AttributeError: 'module' object has no attribute 'Ui_FindAndReplaceDlg'

I got the source code from their website and it errors on the same line in the same way. 我从他们的网站获得了源代码,并以相同的方式在同一行上出错。 I've searched the errata on their webpage with no mention whatsoever. 我在他们的网页上搜索了勘误表,没有任何提及。 Does anyone know what the solution is? 有谁知道解决方案是什么?

The code in question can be found here - https://github.com/suzp1984/pyqt5-book-code/blob/master/chap07/ui_findandreplacedlg.py . 有问题的代码可以在这里找到 - https://github.com/suzp1984/pyqt5-book-code/blob/master/chap07/ui_findandreplacedlg.py If that file is in the same directory as the code you're trying to run, just do 如果该文件与您尝试运行的代码位于同一目录中,那就行了

import ui_findandreplacedlg

You need to convert the ui files using the pyuic tool. 您需要使用pyuic工具转换ui文件。 This is explained in the book as follows (page 206): 本书在下面对此进行了解释(第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. 一旦设计了用户界面并将其保存在.ui文件中,就必须先将其转换为代码才能使用它。 This is done using the pyuic4 command- line program. 这是使用pyuic4命令行程序完成的。 For example: 例如:

 C:\\pyqt\\chap07>pyuic4 -o ui_findandreplacedlg.py findandreplacedlg.ui 

Or if you're on Linux: 或者如果你在Linux上:

$ cd pyqt/chap07
$ pyuic4 -o ui_findandreplacedlg.py findandreplacedlg.ui
$ python findandreplacedlg.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM