我试图使用Pyuic编译一个ui文件,但我无法让它工作......每次我尝试使用命令
pyuic4 -o OutFile_ui.py InFile.ui
它只是给我这个错误
C:\ Windows\system32> pyuic4'pyuic4'未被识别为内部或外部命令,可操作程序或批处理文件.
我实际上不知道pyuic文件应该位于哪里,PyQt应该位于Python文件中还是什么?
请帮忙
我一直在尝试使用python3和Qt4从现有窗口调用一个新窗口.
我使用Qt Designer(主应用程序和另一个)创建了两个窗口,我将Qt Designer生成的.ui文件转换为.py脚本 - 但我似乎无法从主应用程序创建新窗口.
我试过这样做:
############### MAIN APPLICATION SCRIPT ################
from PyQt4 import QtCore, QtGui
import v2
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(194, 101)
self.button1 = QtGui.QPushButton(Form)
self.button1.setGeometry(QtCore.QRect(50, 30, 99, 23))
self.button1.setObjectName(_fromUtf8("button1"))
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(QtGui.QApplication.translate("Form", "Form", None, QtGui.QApplication.UnicodeUTF8))
self.button1.setText(QtGui.QApplication.translate("Form", "Ventana", None, QtGui.QApplication.UnicodeUTF8))
self.button1.connect(self.button1, QtCore.SIGNAL(_fromUtf8("clicked()")), self.mbutton1)
def mbutton1(self):
v2.main()
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form() …Run Code Online (Sandbox Code Playgroud) 我对PyQt还是个新手,但我真的不知道为什么会这样.
我有一个我这样创建的主窗口:
class MainWindow(QtGui.QMainWindow):
#initialize
def __init__(self):
#Call parent constructor
super(MainWindow, self).__init__()
#Load the interface
self.ui = uic.loadUi(r"Form Files/rsleditor.ui")
#Show the ui
self.ui.show()
Run Code Online (Sandbox Code Playgroud)
当我想用以下方法覆盖close事件时:
def closeEvent(self, event):
quit_msg = "Are you sure you want to exit the program?"
reply = QtGui.QMessageBox.question(self, 'Message',
quit_msg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
self.saveSettings()
event.accept()
else:
event.ignore()
Run Code Online (Sandbox Code Playgroud)
我读过我必须把uic.loadUI电话换成:
self.ui = uic.loadUi(r"Form Files/rsleditor.ui", self)
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时,我的所有行为都开始被掀起三次.我很确定我在添加它之前正确设置信号和插槽.有帮助吗?
pyuic文件:
RSLEditorClass.setIconSize(QtCore.QSize(24, 24))
self.centralWidget = QtGui.QWidget(RSLEditorClass)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.centralWidget.sizePolicy().hasHeightForWidth())
self.centralWidget.setSizePolicy(sizePolicy)
self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
self.vLayMain = QtGui.QVBoxLayout(self.centralWidget) …Run Code Online (Sandbox Code Playgroud) 当我在Windows上使用此命令时:
python -m PyQt4.uic.pyuic user_interface.ui -o user_interface.py
Run Code Online (Sandbox Code Playgroud)
之后,我添加了一个资源:
pyrcc4.exe -py3 images.qrc -o images.py
Run Code Online (Sandbox Code Playgroud)
最后,我得到了两个漂亮的文件user_interface.py和images.py。问题是user_interface.py文件以以下代码结尾:
... all QT stuff here.
import images_re
Run Code Online (Sandbox Code Playgroud)
而且由于这是许多父母调用的模块,因此必须像这样导入:
import myapp.gui.images_re
Run Code Online (Sandbox Code Playgroud)
当我更改代码行时,它可以正常工作,但是每次我修改user_interface.ui文件然后执行批处理时,它将被覆盖,因此每次都必须手动对其进行更改。
有什么方法可以告诉pyuic在该import语句中写什么?
还是在pyuic之后可以执行并更改该行代码的任何批处理代码?
还是对调用user_interface.py的.py文件进行一些调整,例如更改默认目录,以便从那里导入images_re?
我的问题是:如何更改标签中的文字?标签在布局中,但setText()似乎不起作用 - 也许我做得不对.
这是我的代码:
这是主窗口GUI,一个Qt-Designer给出:
class Ui_dashboard(QtGui.QMainWindow):
def setupUi(self, dashboard):
dashboard.setObjectName(_fromUtf8("dashboard"))
dashboard.resize(734, 703)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(_fromUtf8("../../../../Documents and Settings/cgarcia/Escritorio/metromara - imagenes - nerio/logoM.JPG")), QtGui.QIcon.Normal, QtGui.QIcon.Off)
dashboard.setWindowIcon(icon)
dashboard.setWindowOpacity(1.0)
self.centralwidget = QtGui.QWidget(dashboard)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.frame = QtGui.QFrame(self.centralwidget)
self.frame.setGeometry(QtCore.QRect(30, 20, 261, 119))
self.frame.setFrameShape(QtGui.QFrame.Box)
self.frame.setFrameShadow(QtGui.QFrame.Plain)
self.frame.setObjectName(_fromUtf8("frame"))
self.gridLayout = QtGui.QGridLayout(self.frame)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.label_5 = QtGui.QLabel(self.frame)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.label_5.setFont(font)
self.label_5.setObjectName(_fromUtf8("label_5"))
self.gridLayout.addWidget(self.label_5, 4, 0, 1, 1)
self.label_4 = QtGui.QLabel(self.frame)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.label_4.setFont(font)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.gridLayout.addWidget(self.label_4, 3, 0, 1, 1)
self.label_ci = QtGui.QLabel(self.frame) …Run Code Online (Sandbox Code Playgroud) 我开始学习 Python 和 PyQt。目前,我正在解决一个关于连接信号和插槽的非常基本的问题,使用从 QDesigner 生成的对话框表单。我想从 QDialog 连接一个按钮。该代码不会产生错误。正如预期的那样,对话框显示出来。但是点击按钮没有任何反应。
或者,我尝试将代码表单Ui_Dialog直接包含在我的目标类中Testdialog。然后连接正常工作。似乎我在从Ui_DialogtoTestdialog和/或我想要执行对话框的方式继承属性时犯了一个错误。
我的主程序如下所示:
from __future__ import unicode_literals
import sys
from PyQt4 import *
from PyQt4 import QtGui
from PyQt4.QtCore import SIGNAL, QObject
import UI_Test
class Testdialog(QtGui.QDialog, UI_Test.Ui_Dialog):
def __init__(self,parent=None):
super(Testdialog, self).__init__(parent)
self.setupUi(self)
print("Connect buttons") # gives the expected output
self.connect(self.pushButton_Ok, SIGNAL("clicked()"), self.clickedOk)
self.connect(self.pushButton_Cancel, SIGNAL("clicked()"), self.clickedCancel)
# Alternativly I have tríed the following without improvement:
# self.pushButton_Ok.clicked.connect(self.clickedOk)
# QObject.connect(self.pushButton_Cancel, SIGNAL("clicked()"), self.clickedCancel)
def clickedCancel(self):
print ("Cancel") # …Run Code Online (Sandbox Code Playgroud) 注意:我已经读过这篇文章,但不幸的是我没有理解它。我的目录设置有点像这样:
Main_Folder
|_ Base_Gui_File.py
|_ Child_directory (a directory inside Main_Folder)
|_ __init__.py
|_ some_other.py
Run Code Online (Sandbox Code Playgroud)
Base_Gui_File.py我已经在文件中找到了从(PyQt4)生成的所有 GUI 代码designer。有一个文本输入字段QLineEdit、一个按钮QPushButton和一个文本区域QTextBrowser。
默认情况下QTextBrowser是隐藏的。但是,我想做的是,当有人在 中键入某些内容QLineEdit并单击 时QPushButton,它会将字符串发送到 中文件中的QLineEdit方法。在对该字符串执行某些操作后,文件中的方法将在中打印一些内容。some_other.pyChild_Directorysome_other.pyshowQTextBrowserBase_Gui_File.pyQTextBrowser
到目前为止,我已经能够Base_GUI_File.py通过some_other.py从QLineEdit. 这是两个文件的代码:
some_other.py:
import sys
sys.path.append("..")
from Base_Gui_File import Ui_MainWindow
class childone(object):
"""docstring for childone"""
def __init__(self):
super(childone, self).__init__()
def somemethod(self, url):
pass
print 'Hey!'
final_string …Run Code Online (Sandbox Code Playgroud) 我正在尝试将 QTDesigner 创建的 ui 文件转换为 py 文件。但我收到错误: pyuic5 未被识别为内部或外部命令。我使用 anaconda 3,并尝试了这里的所有建议:
我在这里看到:
嗨,也许这是一个愚蠢的问题,但我找不到错误或我该怎么做才能做到这一点......
我有一个.ui文件,我的GUI是在QT Designer上设计的,我希望将它与Python一起使用.我已经安装了Anaconda 2(Python 2.7)和Python 3.6,但是当我在pyuic.py所在的文件夹中运行命令时(C:\ Python36\Lib\site-packages\PyQT5\uic)
python pyuic.py -o mainwindow.ui
Run Code Online (Sandbox Code Playgroud)
我有以下错误
Traceback (most recent call last):
File "pyuic.py", line 28, in <module>
from .driver import Driver
ModuleNotFoundError: No module named '__main__.driver'; '__main__' is not a package
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我为什么以及如何解决它?
提前致谢!
我想通过直接导入 .ui 文件来使用使用 QtCreator 创建的自定义小部件。目前我的代码在使用时工作正常pyuic5目前,当我用来创建 .py 文件但我希望能够直接从 .ui 文件导入我的小部件。一些工作代码:
主要.py
import MyWidget
MainWindowUI, MainWindowBase = uic.loadUiType('main.ui')
class mainGUIWindow(MainWindowUI, MainWindowBase):
def __init__(self, mainWindow):
QtWidgets.QMainWindow.__init__(self)
self.setupUi(self)
self.myWidget = MyWidget.Ui_Form()
self.myWidget.setupUi(self)
Run Code Online (Sandbox Code Playgroud)
MyWidget.py(通过生成pyuic5 -x MyWidget.ui -o MyWidget.py)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(271, 201)
# The rest of the widget is down here
Run Code Online (Sandbox Code Playgroud)
有没有办法使用LoadUi()或类似的方法来避免使用pyuic?到目前为止我已经尝试过:
主要.py
class mainGUIWindow(MainWindowUI, MainWindowBase):
def __init__(self, mainWindow):
QtWidgets.QMainWindow.__init__(self)
self.setupUi(self) # contains a QFrame called 'frame'
# Creation of myWidget
self.wid = …Run Code Online (Sandbox Code Playgroud) pyuic ×10
pyqt ×9
python ×7
pyqt4 ×3
qt-designer ×3
pyqt5 ×2
anaconda ×1
cmd ×1
external ×1
python-2.7 ×1
qaction ×1
qlabel ×1
qpushbutton ×1
qt-creator ×1
rcc ×1
text ×1
window ×1