Python Forum
[PyQt] [Solved]Converting .ui to .py
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] [Solved]Converting .ui to .py
#1
Hello,

I used QT Designer (This one here: QT Designer Link) and I'm wondering how to convert the UI file that I have to a useable Python file?

I keep seeing tutorials using "pyuic5" but it doesn't work for me (I even tried pyuic6, since the designer uses pyQt6, but no luck.)
I just get:
pyuic6' is not recognized as an internal or external command,
operable program or batch file.


Any help is greatly appreciated.

Thanks in advance.
Reply
#2
What do you mean by "doesn't work for me"? What did you try to do and what happened that makes you think it doesn't work.

pyuic5 doesn't make a Python program you can run. It creates a python class that you can use in your Python program. You still have to write something like shown below. In the example, "MainWindow.py" is the file generated by pyuic5.
import sys
from PyQt6 import QtWidgets, uic

from MainWindow import Ui_MainWindow


class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, *args, obj=None, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        self.setupUi(self)


app = QtWidgets.QApplication(sys.argv)

window = MainWindow()
window.show()
app.exec()
You don't need to convert your ui design to Python to use it. You can load the ui file like this:
import sys
from PyQt6 import QtWidgets, uic

app = QtWidgets.QApplication(sys.argv)

window = uic.loadUi("mainwindow.ui")
window.show()
app.exec()
(examples from https://www.pythonguis.com/tutorials/pyq....%20python)
Reply
#3
pip install pyqt6-tools
Reply
#4
perhaps: https://pypi.org/project/pyqt6rc/ I have never used, so this is all I have to offer.
Reply
#5
(May-11-2022, 09:11 PM)Axel_Erfurt Wrote: pip install pyqt6-tools

Thanks, that worked. I guess I was missing it.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020