How to display images inside the new tab in Python
<p>Suppose that I have 10 images in a directory, and need them to be displayed inside a newly created tab once the user presses a push-button. The images must be displayed according to a 5x5 grid with a proper image label. </p>

<p>I have designed a GUI using Qt Designer containing three different tabs (tab1, tab2 and tab3), but it seems like this will not work for me - the images wouldn't display inside tab3. How can I make it done by using command-line coding rather than using Qt Designer in order to display all the images?</p>

<p>Below is the function to display the images:</p>

<pre><code># Display image at 'Tab 3' once user press button 'Display'
def display_result(self):

    # Get wafer qty
    qty = int(self.qty_selected)
    print('qty -&gt; ' + str(qty))

    # Get lot id
    name = str(self.lotId)
    print ('lotId -&gt; ' + str(name))

    for index in range(int(qty)):   
        pixmap = QtGui.QPixmap()
        path = r'c:\Users\mohd_faizal4\Desktop\Python\Testing\%s\%s_%d.jpeg' % (name, name, index + 1)
        print('load (%s) %r' % (pixmap.load(path), path))
        item = QtGui.QListWidgetItem(os.path.basename(path))
        item.setIcon(QtGui.QIcon(path))
        self.viewer.addItem(item)


    contents = QtGui.QWidget(self.tabWidget)
    layout = QtGui.QVBoxLayout(contents)
    self.tabWidget.addTab(contents, 'Tab 4')
</code></pre>

<p>I would like to display all the images inside 'Tab 4', instead of opening a another window.</p>

<p><a href="https://i.stack.imgur.com/TcMm3.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/TcMm3.jpg" alt="tab 3"></a>      </p>

<p>You can easly display an image inside the tab by creating a label in the tab, here is an example for that : ( the tab in my example is tab_3)</p>

<p><code>def setupUi(self, MainWindow):
        self.label = QtWidgets.QLabel(self.tab_3)
        self.label.setGeometry(QtCore.QRect(340, 30, 241, 171))
        self.label.setText("")
        self.label_181.setPixmap(QtGui.QPixmap("images/A_01.png"))
        self.label.setScaledContents(True)
        self.label.setObjectName("label")</code></p>

<p>so here you will get the image inside the tab.I hope that will help you.</p>

python image user-interface tabs pyqt