![](/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.