Overview
This article implements the following program: ( in the form of painting the [-100, 100] Two period of the sine function image )
The main steps are as follows:
1. Create a new project in Eric6, create a new form
2, (automatically open) into PyQt5 Desinger, edit the GUI, save
3, back to Eric 6, to the previous step to get the interface file Drawing.ui file right-click, compile the form, get ui_drawing.py file
4, then right-click on the Drawing.ui file, generate dialog code, get drawing.py file. ( add your own program logic in drawing.py )
5, Py2exe package into EXE file (this step)
Body
Next to "Overview" Step 4th:
In drawing.py, the paint event is defined first:
def paintevent (Self, event): = Qtgui.qpainter () qp.begin (self) self.drawpoints (QP) #自定义画点方法 qp.end ()
Then, customize the Draw point method :
def drawpoints (self, qp): qp.setpen (QtCore.Qt.red) = self.size () for in range: # [-100, 100] Two period sine function image x = -1+2.0*i/ + size.width ()/2.0 = -50*math.sin ((x-size.width ()/2.0) *math.pi/50) + size.height ()/2.0 qp.drawpoint (x, y)
Together, drawing.py is like this:
#-*-coding:utf-8-*-"""Module implementing Drawing."""Importsys, Math fromPyQt5ImportQtgui, Qtcore fromPyqt5.qtwidgetsImportQdialog, Qapplication fromUi_drawingImportui_drawingclassDrawing (Qdialog, ui_drawing):def __init__(Self, parent=None): Super (Drawing, self).__init__(parent) self.setupui (self)defpaintevent (Self, event): QP=Qtgui.qpainter () qp.begin (self) self.drawpoints (QP)#自定义画点方法qp.end ()defdrawpoints (Self, QP): Qp.setpen (QtCore.Qt.red) Size=self.size () forIinchRange (1000): #[-100, 100] Two-period sine function imagex = * ( -1+2.0*i/1000) + size.width ()/2.0y= -50*math.sin ((x-size.width ()/2.0) *math.pi/50) + size.height ()/2.0qp.drawpoint (x, y)if __name__=='__main__': App=qapplication (SYS.ARGV) dlg=Drawing () dlg.show () Sys.exit (App.exec_ ())
(Welcome reprint, but please keep the author's name and the original link.) )
Using ERIC6 and PYQT5 to achieve Python's extreme GUI Programming (series)----Drawing (Drawing) (2)--Draw points