Jul-12-2019, 05:04 PM
(This post was last modified: Jul-12-2019, 05:04 PM by Man_from_India.)
I am a very new to Python. I have no prior experience in this field, so in order to learn programming, I started to learn Python on my own. To create a simple GUI I am using PyQt5 module. I wrote this code:
Now I think the button is changing shape. I asked this on StackOvetflow, and they said it might be possible because of the size policy of the button. They shared this link
But when I read the document, I got that when the layout is present like the way it is in my code, the size policy of the button should not work, the resize of the button or similar behavior is taken care of by the layout. Though there is no size policy property in Qlayout or QGridlayout.
![[Image: 41pwc.jpg]](https://i.stack.imgur.com/41pwc.jpg)
Why is it contradicting with the official document? I am confused, and must be missing something. Please help me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
from PyQt5 import QtWidgets from PyQt5.QtWidgets import * def button_clicked(): global num num + = 1 button.setText( "Click on me" ) label1.setText( f "Button is pressed {num} times." ) label2.setText( "You are welcome to my GUI. I am trying to stretch the label" + f "\nThis is {num} times" + "\nI am welcoming you." ) num = 0 app = QtWidgets.QApplication([]) label1 = QtWidgets.QLabel( "Hello World." ) label2 = QtWidgets.QLabel( "You are welcome to my GUI." ) button = QtWidgets.QPushButton( "Click on me. I am waiting" ) window = QWidget() layout = QGridLayout(window) layout.addWidget(label1, 1 , 1 ) layout.addWidget(label2, 2 , 1 ) layout.addWidget(button, 2 , 4 ) button.clicked.connect(button_clicked) window.show() window.setGeometry( 100 , 100 , 280 , 100 ) app. exec () |
But when I read the document, I got that when the layout is present like the way it is in my code, the size policy of the button should not work, the resize of the button or similar behavior is taken care of by the layout. Though there is no size policy property in Qlayout or QGridlayout.
![[Image: 41pwc.jpg]](https://i.stack.imgur.com/41pwc.jpg)
Why is it contradicting with the official document? I am confused, and must be missing something. Please help me.