Skip to content

Instantly share code, notes, and snippets.

@Park-Developer
Created January 1, 2021 05:58
Show Gist options
  • Save Park-Developer/ea9e3d85409a1c97959263a293b90b28 to your computer and use it in GitHub Desktop.
Save Park-Developer/ea9e3d85409a1c97959263a293b90b28 to your computer and use it in GitHub Desktop.
pyqt5 : Qlabel size setting
rom PyQt5.QtWidgets import *
from PyQt5 import QtCore
from PyQt5.QtGui import *
import sys
class Window(QMainWindow):
def __init__(self):
super().__init__()
# set the title
self.setWindowTitle("Label")
# setting the geometry of window
self.setGeometry(0, 0, 400, 300)
# creating a label widget
self.label_1 = QLabel("== Normal Label ====", self)
# moving position
self.label_1.move(100, 100)
# setting up border
self.label_1.setStyleSheet("border: 1px solid black;")
# creating a label widget
self.label_2 = QLabel("====== Adjusted label =====", self)
# moving position
self.label_2.move(100, 150)
# setting up border
self.label_2.setStyleSheet("border: 1px solid black;")
# adjusting the size of label
self.label_2.adjustSize()
# show all the widgets
self.show()
# create pyqt5 app
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
@Park-Developer
Copy link
Author

Park-Developer commented Jan 1, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment