简体   繁体   English

无法从 PyQt5 导入 uic

[英]Can't import uic from PyQt5

I am trying to load my .ui file in python and i want to use uic.loadUI() function but I have problem with importing it, I get an error:我正在尝试在 python 中加载我的 .ui 文件,我想使用uic.loadUI()函数,但导入它时遇到问题,我收到一个错误:

*Cannot find reference 'uic' in '__init__.pyi'*

My code:我的代码:

from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5 import uic
import sys

class UI(QWidget):
    def __init__(self):
        super().__init__()
        uic.loadUi("mybutton.ui", self)

app = QApplication([])
window = UI()
window.show()
app.exec_()

I am using python 3.9.7.我正在使用 python 3.9.7。 Installed PyQt5 with pip.使用 pip 安装 PyQt5。 Checked the PyQt5 folder and it looks like this: https://i.stack.imgur.com/bTlXs.png检查了 PyQt5 文件夹,它看起来像这样: https ://i.stack.imgur.com/bTlXs.png

Can You please help?你能帮忙吗?

I had a simular problem when using PyCharm.我在使用 PyCharm 时遇到了一个类似的问题。 The following Code fixed the issue:以下代码修复了该问题:

from PyQt5.uic import loadUiType
from os import path
FORM_CLASS, _ = loadUiType(path.join(path.dirname(__file__), "mybutton.ui"))

I Think its a Bug from PyCharm我认为这是 PyCharm 的错误

Filip 在哪里放置 FORM_CLASS, _ = loadUiType(path.join(path.dirname( file ), "mybutton.ui"))

loadUi(path.join(path.dirname( file ), "w.ui"),self)

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

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