PyQt筆記001——入門小窗口

PyQt筆記001——入門小窗口

第一個窗口

import sys
from PyQt5 import QtWidgets

# pyqt窗口必須在QApplication方法中使用
app = QtWidgets.QApplication(sys.argv)

label = QtWidgets.QLabel("<p style='color: red; margin-left: 20px'><b>hell world</b></p>")  # qt支持html標籤,強大吧
# 有了實例,就需要用show()讓他顯示
label.show()

sys.exit(app.exec_())

第二個窗口

from PyQt5 import QtWidgets
# 從PyQt庫導入QtWidget通用窗口類
class mywindow(QtWidgets.QWidget):
    # 自己建一個mywindows類,以class開頭,mywindows是自己的類名,
    # (QtWidgets.QWidget)是繼承QtWidgets.QWidget類方法,
    def __init__(self):
        super(mywindow, self).__init__()
import sys
app = QtWidgets.QApplication(sys.argv)
windows = mywindow()
windows.setWindowTitle('Simple') # 窗口標題
windows.resize(300,300) # 窗口大小
windows.move(0,0) #窗口位置(距離上邊框和左邊框)
label = QtWidgets.QLabel(windows)  # 在窗口中綁定label
label.setText("hello world")

windows.show()
sys.exit(app.exec_())
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章