Popular Posts

Tuesday, February 28, 2023

PyQt WIndow setting

Hello Python Developer!

How are you? Hope you're in the best condition today. Because we will exercise PyQt WIndow setup.


-PyQt wIndow Size adjustment

import sys
from PyQt5.QtWidgets import *

class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setGeometry(200,200,400,300)
       
app = QApplication(sys.argv)
window = MyWindow()
window.show()
app.exec_()


Python codes running result


- PyQt titlebar & icon setting

* Note : An icon file "PyQt window sample icon.png" must be in the same folder with this Python code.  

import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *

class MyWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setGeometry(200,200, 300,150)
        self.setWindowTitle("PyQt exercise")
        self.setWindowIcon(QIcon("PyQt window sample icon.png"))
       
app = QMainWindow(sys.argv)
window = MyWindow()
window.show()
app.exec_()

Have you checked above PyQt exercise sample Python codes? Great job!

Let's learn more about PyQt window setup!

No comments:

Post a Comment

Python - Web crawling exercises

Hello Python developer! How are you? Hope you've been good and had wonderful time with Python. There are 10 Python requests module exerc...