I've recently switched over from running my .ui file through the pyuic5 command line tool to importing the .ui file by calling uic.loadUi. I decided to go back through some of the tutorials I'd previously done using the command line converter and see if I can get them working using loadUi.
One of them will crash as soon as I click a button but I don't get any useful debug info.
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QLabel
from PyQt5 import uic
import sys
from PyQt5.uic.properties import QtGui
class UI(QMainWindow):
def __init__(self):
super(UI, self).__init__()
uic.loadUi('catdog.ui', self)
self.picture = self.findChild(QLabel, 'picture')
self.cat = self.findChild(QPushButton, "cat")
self.cat.clicked.connect(self.show_cat)
self.dog = self.findChild(QPushButton, "dog")
self.dog.clicked.connect(self.show_dog)
self.show()
def show_dog(self):
self.picture.setPixmap(QtGui.QPixmap("dog.JPG"))
def show_cat(self):
self.picture.setPixmap(QtGui.QPixmap("cat.JPG"))
app = QApplication(sys.argv)
UIWindow = UI()
app.exec_()
I suspect it's something to do with the findChild(QPushButton) but I'm a bit lost.
The console just give me this- Process finished with exit code -1073740791 (0xC0000409)
for reference, here's the .ui XML-
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>491</width>
<height>391</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QWidget" name="gridLayoutWidget">
<property name="geometry">
<rect>
<x>-1</x>
<y>-1</y>
<width>491</width>
<height>391</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="picture">
<property name="text">
<string/>
</property>
<property name="pixmap">
<pixmap>cat.JPG</pixmap>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="cat">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Cat</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignTop">
<widget class="QPushButton" name="dog">
<property name="font">
<font>
<pointsize>16</pointsize>
</font>
</property>
<property name="text">
<string>Dog</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</widget>
<resources/>
<connections/>
</ui>
User contributions licensed under CC BY-SA 3.0