PyQT5 — Python Tutorial – PyQT5 Window

pyqt5 tutorials

Today, I am writing the label and text fields that I set as the second section.
With this section, we will begin to fill the Windows we create slowly.
Now let’s start building our window.

PyQT5 Building Window

from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
app = QApplication(sys.argv)
window = Window()
window.show()
app.exec_()

PyQT5 How to use Label

from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.etiket = QLabel(“try”,self)
app = QApplication(sys.argv)
window = Window()
window.show()
app.exec_()

in the second example, you can use the settext(“text”) method.

from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
#create simple grid
self.grid = QVBoxLayout(self)
# create tag
#sample 2
self.etiket2 = QLabel(self)
self.etiket2.setText(“try2”)
#addwidget
app = QApplication(sys.argv)
window = Window()
window.show()
app.exec_()

There’s no difference between the two. If you look at the code block below, it will be better for you.

note: a small grid structure was used because of the overlapping of the writings.

from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
#create a simple grid
self.grid = QVBoxLayout(self)
# creating tags
#sample 1
self.etiket = QLabel(“deneme”,self)
#sample 2
self.etiket2 = QLabel(self)
self.etiket2.setText(“deneme2”)
#addwidget
self.grid.addWidget(self.etiket)
self.grid.addWidget(self.etiket2)
app = QApplication(sys.argv)
window = Window()
window.show()
app.exec_()

with the settext method, you can change label names later.

self.etiket.setText(“try3”)

PyQT5 LineEdit

This section is not an action, so I’m showing it directly in code. With QlineEdit, we create an input-like field in the XML

self.lineEdit = QLineEdit(self)

If you say that you can set password protection for the input field with setEchoMode.

self.lineEdit.setEchoMode(QLineEdit.Password)

Now, let’s create a small entrance area. as a warning to do with QtDesigner, just pay attention to the label and lineEdit fields.

from PyQt5.QtWidgets import *
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
#create grid
self.grid = QVBoxLayout(self)
#create labels
self.label_ad = QLabel(“id: “,self)
self.label_sifre = QLabel(“password: “,self)
#lineEdit(input) create
self.ad=QLineEdit(self)
self.sifre=QLineEdit(self)
#design password line:****
self.sifre.setEchoMode(QLineEdit.Password)
self.grid.addWidget(self.label_ad)
self.grid.addWidget(self.ad)
self.grid.addWidget(self.label_sifre)
self.grid.addWidget(self.sifre)
app = QApplication(sys.argv)
window = Window()
window.show()
app.exec_()

We’re developing ourselves now. In the next article we will see the lists, combobox fields. Today we will write articles about buttons and proceed with more beautiful examples.

 

https://www.kalogroup.com.au/