我尝试使用.ui
将.py
文件转换为loadUiTypem
,但是不起作用
from PyQt5.QtGui import*
from PyQt5.QtWidgets import*
from PyQt5.QtCore import*
from PyQt5.uic import loadUiType
import sys
MainUI,_ = loadUiType('main.ui')
class Main(QMainWindow,MainUI):
def __init__(self,parent = None):
super(Main, self).__init__(parent)
QMainWindow.__init__(self)
def main():
app = QApplication(sys.argv)
window = Main()
window.show()
app.exec_()
if __name__ == '__main__':
main()`enter code here
raceback (most recent call last): File "C:/Users/korish/PycharmProjects/library/index.py", line 8, in <module> MainUI,_ = loadUiType('main.ui',"rb") File "C:\Users\korish\PycharmProjects\library\venv\lib\site-packages\PyQt5\uic\__init__.py", line 199, in loadUiType winfo = compiler.UICompiler().compileUi(uifile, code_string, from_imports, resource_suffix, import_from) File "C:\Users\korish\PycharmProjects\library\venv\lib\site-packages\PyQt5\uic\Compiler\compiler.py", line 111, in compileUi w = self.parse(input_stream, resource_suffix) File "C:\Users\korish\PycharmProjects\library\venv\lib\site-packages\PyQt5\uic\uiparser.py", line 1013, in parse document = parse(filename) File "C:\Users\korish\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 1197, in parse tree.parse(source, parser) File "C:\Users\korish\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 587, in parse source = open(source, "rb") FileNotFoundError: [Errno 2] No such file or directory: 'main.ui'