Using ERIC6 and PYQT5 to achieve Python's extreme GUI Programming (series)----Drawing (Drawing) (2)--Draw points

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.