Python 3 PyQt5 Horizontal Box Layout of Buttons Using QHBoxLayout Widget GUI Desktop App

Python 3 PyQt5 Horizontal Box Layout of Buttons Using QHBoxLayout Widget GUI Desktop App

Python 3 PyQt5 Horizontal Box Layout of Buttons Using QHBoxLayout Widget GUI Desktop App

import sys
from PyQt5.QtWidgets import *

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Horizontal Box Layout")
        self.setGeometry(500 , 250 , 400 , 400)
        self.UI()

    def UI(self):
        hbox=QHBoxLayout()
        hbox.addStretch()
        button1=QPushButton("Button1")
        button2=QPushButton("Button2")
        button3=QPushButton("Button3")
        hbox.addWidget(button1)
        hbox.addWidget(button2)
        hbox.addWidget(button3)
        hbox.addStretch()
        self.setLayout(hbox)
        self.show()


def main():
    App = QApplication(sys.argv)
    window=Window()
    sys.exit(App.exec_())
if __name__ == '__main__':
    main()
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment