使用 pyuic 将 .ui 转换为 .py? [英] Convert a .ui into a .py with pyuic?

查看:46
本文介绍了使用 pyuic 将 .ui 转换为 .py?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 OSX 10.8,python 2.7.5

I'm using OSX 10.8, python 2.7.5

我刚刚用 QtDesigner 构建了一个 GUI,我试图弄清楚如何在 Python 中使用它.我发现我必须使用pyuic"以及如何在这里使用:pyqt 在 mac osx snow leopard 中的安装问题,但是按照这里给出的方法给了我一个很好的

I just built a GUI with QtDesigner, and I was trying to figure out how to use it with Python. I found I have to use "pyuic" and how to do it here : pyqt installation problem in mac osx snow leopard, but following the approach given here gave me a pretty nice

pyuic: command not found

欢迎任何有关如何解决此问题的建议

Any advice would be most welcome on how to solve this

推荐答案

我不了解 OSX,但另一个解决方案是使用 uic 模块(pyuic4 只是这个模块的包装器).这是使用名为 mydialog.ui 的 ui 文件的自定义 QDialog 的示例:

I don't know about OSX, but another solution is to use the uic module of PyQt4 (pyuic4 is just a wrapper around this module). Here is an example of a custom QDialog using a ui file called mydialog.ui :

import os

from PyQt4 import QtGui
from PyQt4 import uic

class myDialog(QtGui.QDialog):
  def __init__(self, parent=None):
    QtGui.QDialog.__init__(self, parent)
    uic.loadUi(os.path.join(os.path.dirname(os.path.abspath(__file__)),"mydialog.ui"), self)

请注意,loadUi 方法的最后一个参数是 self:这意味着您可以访问所有小部件作为类的属性,即 dialog.textEdit 而不是 dialog.ui.textEdit.

Note that the loadUi method last argument is self: this means that you will have access to all widgets as attributes of your class, ie dialog.textEdit instead of dialog.ui.textEdit.

这篇关于使用 pyuic 将 .ui 转换为 .py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆