https://github.com/hrassi/pyqt5_starter
https://github.com/hrassi/pyqt5_starter
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hrassi/pyqt5_starter
- Owner: hrassi
- Created: 2024-02-04T09:36:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-04T10:05:40.000Z (over 2 years ago)
- Last Synced: 2025-03-17T18:51:55.152Z (over 1 year ago)
- Language: Python
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.txt
Awesome Lists containing this project
README
# PyQt5_Starter
this is a starter kit to begin with Pyqt5
u can use also qt designer app that help a lot to reduce writing code
qt designer is an app for gui designing interface
it will give u a file.ui usable witch will be translated to python
********************************************************************
python PyQt5 :
frame button image label
import sys
from PyQt5.QtWidgets import QApplication, QLabel, QPushButton, QVBoxLayout, QWidget, QFileDialog, QGridLayout,QLineEdit
from PyQt5.QtGui import QPixmap
from PyQt5 import QtGui, QtCore
from PyQt5.QtGui import QCursor
full tutorial:
https://youtu.be/9iZLDnW_vwU?si=jGDlj90v0veZnMj0
QGrid Layout :
https://www.pythontutorial.net/pyqt/pyqt-qgridlayout/
# example 1 label:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QFont
app=QApplication([])
window=Qwidget()
window.setGeometry(100,100,200,300) window coordinate and dimmentions
window.setWindowTitle(“Houssam App”)
label=QLabel(window)
label.setText(“hello world”)
label.setFont(QFont(“Arial”,16))
label.move(50,100) #coordinate of label
window.show()
app.exec_()
if __name__ == ‘ __main__’:
main()
# example 2 layout QVBoxLayout and push button
# and label and text box:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QFont
app=QApplication([])
window=Qwidget()
window.setGeometry(100,100,200,300)
window.setWindowTitle(“Houssam App”)
label = QLabel(“Press the button “)
textbox=QTextEdit()
button = QPushButton(“Press Me !”)
button.clicked.connect(on_click)
button2 = QPushButton(“send msg”)
button2.clicked.connect(lambda: on_click2(textbox.toPlainText()))
layout.addWidget(label)
layout.addWidget(button)
layout.addWidget(button2)
layout.addWidget(textbox)
window.setLayout(layout)
window.show()
app.exec_()
def on_click():
print(“Hello world”)
message = QMessageBox()
message.setText(“Hello world”)
message.exec_()
def on_click2(msg):
message.setText(msg)
message.exec_()
if __name__ == ‘ __main__’:
main()
QT Designer :
https://youtu.be/MOItX2aKTGc?si=HxK15KkHKEDYCnI6
from PyQt5.QtWidgets import *
from PyQt5 import uic
class MyGUI(QMainWindow):
def __init__(self):
super(MyGUI,self).__init__()
uic.loadUi(“mygui.ui” , self) # mygui.ui is the file from QT Designer
self.show()
self.pushButton.clicked.connect(self.login) # if pushButton is pushed
self.pushButton_2.clicked.connect(lambda: self.sayit(self.textEdit.toPlainText()
self.actionClose.triggered.connect(exit)
def login(self):
if self.lineEdit.text() == “hrassi” and self.lineEdit_2.text() == “password”:
self.textEdit.setEnabled(True)
self.pushButton_2.setEnabled(True)
else:
message = QMessageBox()
message.setText(“invalid login”)
message.exec_()
def sayit(self, msg):
message = QMessageBox()
message.setText(msg)
message.exec_()
def main():
app = QApplication([])
window = MyGUI()
app.exec_()
if __name__ == ‘ __main__’:
main()
QT DESIGNER TUTORIAL : youtube NeuralNine chanel
https://youtu.be/MOItX2aKTGc?si=HxK15KkHKEDYCnI6
https://youtu.be/vde95l737PI?si=9fTxVxOJOVkuvl1A
using color and properties and layout:
https://youtu.be/i_Z-1F_U_yw?si=MPfgtebC0dW6Q2WO