python画圆函数方法 python里怎么画圆

python turtle画4个同心圆方法import turtle
#draw first circle
turtle.penup()
turtle.goto(0,-200)
turtle.pendown()
turtle.circle(200)
#draw second circle
turtle.penup()
turtle.goto(0,-150)
turtle.pendown()
turtle.circle(150)
#draw third circle
turtle.penup()
turtle.goto(0,-100)
turtle.pendown()
turtle.circle(100)
#draw fourth circle
turtle.penup()
turtle.goto(0,-50)
turtle.pendown()
turtle.circle(50)
画笔的坐标默认在0,0,就以它为圆心 。
因为turtle画圆的时候是从圆的底部开始画的 , 所以需要找到四个圆底部的坐标
比如:
第一个半径为200的圆 , 底部为(0,-200)
第二个半径为150的圆,底部为(0,-150)
第三个半径为100的圆,底部为(0,-100)
第四个半径为50的圆 , 底部为(0,-50)
画的时候按下面的步骤:
抬起画笔:turtle.penup()
移动到相应坐标:turtle.goto(坐标)
放下画笔:turtle.pendown()
画圆:turtle.circle(半径)
效果如下图所示:
python pyqt怎么画圆这个例子我做了好几天:
1)C++的源码 , 改写成PyQt5版本的代码,好多细节不会转化
2)网上的PyQt的例子根本运行不了
填了无数个坑,结合二者,终于能完成了一个关于绘图的东西 。这个过程也掌握了很多新的知识点
【知识点】
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 会报错!========= 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()

推荐阅读