QT4 Tabs

Tabs are very useful in graphical applications. They appear in webbrowsers, text editors and any other apps.  To create a tabbed window, you need to call the  QTabWidget()  function.  Every tab is a QWidget() which you have seen before.  You can connect the QWidgets with the QTabWidget with the function:

tabs.addTab(tab1,"Tab 1")

where the first parameter is the tab object and the second the name that appears on the screen. We added some buttons to the first tab (QWidget).

Related course:
Create Simple GUI Applications with Python and Qt

Example code:

from PyQt4 import QtGui
from PyQt4 import QtCore
import sys
def main():
    app 	= QtGui.QApplication(sys.argv)
    tabs	= QtGui.QTabWidget()
    # Create tabs
    tab1	= QtGui.QWidget()	
    tab2	= QtGui.QWidget()
    tab3	= QtGui.QWidget()
    tab4	= QtGui.QWidget()
    # Resize width and height
    tabs.resize(250, 150)
    # Set layout of first tab
    vBoxlayout	= QtGui.QVBoxLayout()
    pushButton1 = QtGui.QPushButton("Start")
    pushButton2 = QtGui.QPushButton("Settings")
    pushButton3 = QtGui.QPushButton("Stop")
    # Add tabs
    tabs.addTab(tab1,"Tab 1")
    tabs.addTab(tab2,"Tab 2")
    tabs.addTab(tab3,"Tab 3")
    tabs.addTab(tab4,"Tab 4") 
    # Set title and show
    tabs.setWindowTitle('PyQt QTabWidget @ pythonspot.com')
if __name__ == '__main__':


PyQT Tabs
PyQT Tabs

Download PyQT Code (Bulk Collection)

2 thoughts on “QT4 Tabs

  1. Thor - May 17, 2015

    Okay, I tried the sample…I’m officially impressed…
    Python as the vehicle of choice for desktop programs…
    Thanks 🙂

    1. Frank - May 17, 2015

      Awesome! There will be more tutorials soon, I may write some this evening.