定义函数画圆Python 用python绘制函数图形( 三 )


eval的基本使用格式
1 eval(字符串或字符串变量)
eval("1") 1
Python3中的turtle库中turtle. cricle()如何使用,为什么我改变半径的正负画圆的函数如下
turtle.circle(radius,extent=None, steps=None)
参数分别为半径、弧度和画圆弧线段的数量
半径为负,方向相反的原因可以看下turtle库的源代码
w = 1.0 * extent / steps
w2 = 0.5 * w
l = 2.0 * radius * math.sin(w2*math.pi/180.0*self._degreesPerAU)
if radius0:
l, w, w2 = -l, -w, -w2
时设计模块时,可能就希望用半径的正负控制划线的方向
python pyqt怎么画圆这个例子我做定义函数画圆Python了好几天定义函数画圆Python:
1)C++定义函数画圆Python的源码,改写成PyQt5版本的代码,好多细节不会转化
2)网上的PyQt的例子根本运行不定义函数画圆Python了
填了无数个坑,结合二者,终于能完成了一个关于绘图的东西 。这个过程也掌握了很多新的知识点
【知识点】
1、关于多个点的使用
poitns = [QPoint(10, 80), QPoint(20, 10), QPoint(80, 30), QPoint(90, 70)]
请看:
1# 定义多个点 2points = [QPoint(10, 80), QPoint(20, 10), QPoint(80, 30), QPoint(90, 70)] 34# ===直接使用 points 会报错定义函数画圆Python!========= 5# ... 6elif self.shape == self.Points: 7painter.drawPoints(points) 89elif self.shape == self.Polyline:10painter.drawPolyline(points)11 12elif self.shape == self.Polygon:13painter.drawPolygon(points, 4)14 15# ...16 17# ===把 points 用 QPolygon()包裹起来才正确!=========18# ...19elif self.shape == self.Points:20painter.drawPoints(QPolygon(points))21 22elif self.shape == self.Polyline:23painter.drawPolyline(QPolygon(points))24 25elif self.shape == self.Polygon:26painter.drawPolygon(QPolygon(points), 4)27 28# ...
2、在QDialog窗体中显示QWidget部件
【效果图】
【资源】
【代码】
import sysfrom PyQt5.QtCore import *from PyQt5.QtGui import *from PyQt5.QtWidgets import *class StockDialog(QWidget):def __init__(self, parent=None):
super(StockDialog, self).__init__(parent)
self.setWindowTitle("利用QPainter绘制各种图形")
mainSplitter = QSplitter(Qt.Horizontal)
mainSplitter.setOpaqueResize(True)
frame = QFrame(mainSplitter)
mainLayout = QGridLayout(frame)#mainLayout.setMargin(10)
mainLayout.setSpacing(6)
label1=QLabel("形状:")
label2=QLabel("画笔线宽:")
label3=QLabel("画笔颜色:")
label4=QLabel("画笔风格:")
label5=QLabel("画笔顶端:")
label6=QLabel("画笔连接点:")
label7=QLabel("画刷风格:")
label8=QLabel("画刷颜色:")
self.shapeComboBox = QComboBox()
self.shapeComboBox.addItem("Line", "Line")
self.shapeComboBox.addItem("Rectangle", "Rectangle")
self.shapeComboBox.addItem('Rounded Rectangle','Rounded Rectangle')
self.shapeComboBox.addItem('Ellipse','Ellipse')
self.shapeComboBox.addItem('Pie','Pie')
self.shapeComboBox.addItem('Chord','Chord')
self.shapeComboBox.addItem('Path','Path')
self.shapeComboBox.addItem('Polygon','Polygon')
self.shapeComboBox.addItem('Polyline','Polyline')
self.shapeComboBox.addItem('Arc','Arc')
self.shapeComboBox.addItem('Points','Points')
self.shapeComboBox.addItem('Text','Text')
self.shapeComboBox.addItem('Pixmap','Pixmap')
self.widthSpinBox = QSpinBox()
self.widthSpinBox.setRange(0,20)
self.penColorFrame = QFrame()
self.penColorFrame.setAutoFillBackground(True)
self.penColorFrame.setPalette(QPalette(Qt.blue))
self.penColorPushButton = QPushButton("更改")
self.penStyleComboBox = QComboBox()
self.penStyleComboBox.addItem("Solid",Qt.SolidLine)
self.penStyleComboBox.addItem('Dash',Qt.DashLine)
self.penStyleComboBox.addItem('Dot',Qt.DotLine)

推荐阅读