資源簡介
用PyQT5+按鈕事件繪制圖形,做了繪制圓形和矩形的demo。
代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
#?Form?implementation?generated?from?reading?ui?file?‘C:\Users\Brent\Desktop\MainWindowAdvanced.ui‘
#
#?Created?by:?PyQt5?UI?code?generator?5.11.2
#
#?WARNING!?All?changes?made?in?this?file?will?be?lost!
import?sys
from?PyQt5.QtWidgets?import?QApplication?QWidget?QPushButton
from?PyQt5.QtGui?import?QPainter?QColor?QPen
from?PyQt5.QtCore?import?pyqtSlot?Qt
class?App(QWidget):
????def?__init__(self):
????????super().__init__()
????????self.title?=?“PyQt5?button“
????????self.left?=?100
????????self.top?=?100
????????self.width?=?1000
????????self.height?=?1000
????????self.draw?=?““
????????self.initUI()
????def?initUI(self):
????????self.setWindowtitle(self.title)
????????self.setGeometry(self.left?self.top?self.width?self.height)
????????“““在窗體內創建button對象“““
????????button?=?QPushButton(“Circle“?self)
????????“““方法setToolTip在用戶將鼠標停留在按鈕上時顯示的消息“““
????????button.setToolTip(“This?is?an?example?button“)
????????“““按鈕坐標x?=?100?y?=?70“““
????????button.move(200?200)
????????button.resize(button.sizeHint())
????????“““按鈕與鼠標點擊事件相關聯“““
????????button.clicked.connect(self.circle)
????????button1?=?QPushButton(“Rectangle“?self)
????????“““方法setToolTip在用戶將鼠標停留在按鈕上時顯示的消息“““
????????button1.setToolTip(“This?is?an?example?button“)
????????“““按鈕坐標x?=?100?y?=?70“““
??
評論
共有 條評論