Convert a .ui into a .py with pyuic?

前端 未结 1 1077
被撕碎了的回忆
被撕碎了的回忆 2021-01-19 06:10

I\'m using OSX 10.8, python 2.7.5

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 h

相关标签:
1条回答
  • 2021-01-19 06:25

    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)
    

    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.

    0 讨论(0)
提交回复
热议问题