2
import sys
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QDialog, QApplication, QWidget
from PyQt5.QtGui import QPixmap
from PyQt5 import uic


class WelcomeScreen(QDialog):
    def __init__(self):
        super(WelcomeScreen, self).__init__()
        uic.loadUi("welcomescreen.ui",self)

app = QApplication(sys.argv)
welcome = WelcomeScreen()
widget = QtWidgets.QStackedWidget()
widget.addWidget(welcome)
widget.setFixedHeight(800)
widget.setFixedWidth(1200)
widget.show()
try:
    sys.exit(app.exec_())
except:
    print("Exiting")

[Errno 2] No such file or directory: 'welcomescreen.ui'

Can anyone please explain this? I am fairly new to PyQt5 and got stuck in this problem. Your kind help will be appreciated.

ekhumoro
  • 107,367
  • 18
  • 208
  • 308
  • Is 'welcomescreen.ui' in your root or in a sub directory? – David sherriff Jan 25 '22 at 08:40
  • Assuming your ui file is in the same direcory as your main.py script: `import os; uic.loadUi(os.path.join(os.path.dirname(os.path.abspath(__file__)), "welcomescreen.ui"))`. – ekhumoro Jan 25 '22 at 17:05

0 Answers0