简体   繁体   中英

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:

    import ui_findandreplacedlg
ImportError: No module named ui_findandreplacedlg

Depending on which version of python I run, I also get:

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 . 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. This is explained in the book as follows (page 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 

Or if you're on Linux:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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