上傳檔案到「pyqt5/CODE/元件使用範例」

This commit is contained in:
M11212051 2024-05-05 22:32:17 +08:00
parent b3af9b76ae
commit 77d16b0368
2 changed files with 83 additions and 0 deletions

View File

@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
'''
簡介
PyQt5中QDialog範例
'''
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class DialogDemo( QMainWindow ):
def __init__(self, parent=None):
super(DialogDemo, self).__init__(parent)
self.setWindowTitle("Dialog 範例")
self.resize(350,300)
self.btn = QPushButton( self)
self.btn.setText("彈出對話方塊")
self.btn.move(50,50)
self.btn.clicked.connect(self.showdialog)
def showdialog(self ):
dialog = QDialog()
btn = QPushButton("ok", dialog )
btn.move(50,50)
dialog.setWindowTitle("Dialog")
dialog.setWindowModality(Qt.ApplicationModal)
dialog.exec_()
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = DialogDemo()
demo.show()
sys.exit(app.exec_())

View File

@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
'''
簡介
PyQt5中 筆刷範例
'''
import sys
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
class Example(QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
self.text = "hello world"
self.setGeometry(100,100, 400,300)
self.setWindowTitle('Draw Demo')
self.show()
def paintEvent(self, event):
qp = QPainter()
qp.begin(self)
qp.setPen(QColor(Qt.red))
qp.setFont(QFont('Arial', 20))
qp.drawText(10,50, "Hello Python")
qp.setPen(QColor(Qt.blue))
qp.drawLine(10,100,100,100)
qp.drawRect(10,150,150,100)
qp.setPen(QColor(Qt.yellow))
qp.drawEllipse(100,50,100,50)
qp.drawPixmap(220,10,QPixmap("./images/python.png"))
qp.fillRect(200,175,150,100,QBrush(Qt.SolidPattern))
qp.end()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())