代码如下:

import turtle
heights = [856, 420,360,260,205]
def main():
t = turtle.Turtle()
t.hideturtle()
for i in range(5):
drawFilledRectangle(t,-200+(76*i),0,76,heights[i]/4,"black","light blue")
displayText(t)
def drawFilledRectangle(t,x,y,w,h,colorP="black",colorF="white"):
t.pencolor(colorP)
t.fillcolor(colorF)
t.up()
t.goto(x,y)
t.down()
t.begin_fill()
t.goto(x+w,y)
t.goto(x+w,y+h)
t.goto(x,y+h)
t.goto(x,y)
t.end_fill()
def displayText(t):
languages = ["haha1", "haha2", "haha3", "haha4", "haha5"]
t.pencolor("blue")
t.up()
for i in range(5):
t.goto((-162+76*i),heights[i] / 4)
t.write(str(heights[i]),align="center",font=("Arial",10,"normal"))
t.goto((-162+76*i),10)
t.write(languages[i],align="center",font=("Arial",10,"normal"))
t.goto(-200,-25)
t.write("haha 统计图",font=("Arial",10,"normal"))
t.goto(-200,-45)
t.write('(哈哈哈哈哈啊哈哈)',font=("Arial",10,"normal"))
main()

效果如下:

使用Python的turtle模块画出简单的柱状图的更多相关文章

  1. 使用Python的turtle模块画出最简单的五角星

    代码如下: import turtle def main(): t = turtle.Turtle() t.hideturtle() lengthOfSize = 200 drawFivePointS ...

  2. Python——用turtle模块画海龟的第一步

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  3. python的turtle模块画折线图

    代码如下: import turtle yValues = [10.0,7.4,6.4,5.3,4.4,3.7,2.6] def main(): t = turtle.Turtle() t.hidet ...

  4. python中turtle模块画正多边形

    画正多边形主要是计算多边形每个角度对应的外角的度数,计算出来这个度数即可画图,相对来说非常简单 以正六边形为例 import turtle import time t = turtle.Pen() f ...

  5. 课程作业——Python基础之使用turtle库画出红旗

    代码如下: import turtle # 设置画笔和背景颜色 turtle.color('yellow') turtle.bgcolor('red') # 通过偏移量和尺寸大小画星星 def dra ...

  6. 一篇文教你使用python Turtle库画出“精美碎花小清新风格树”快来拿代码!

    Turtle库手册可以查询查询 python图形绘制库turtle中文开发文档及示例大全,手册中现有示例,不需要自己动手就可以查看演示. 使用Turtle画树,看了一下网上的代码,基本上核心的方法是使 ...

  7. python中logging模块的一些简单用法

    用Python写代码的时候,在想看的地方写个print xx 就能在控制台上显示打印信息,这样子就能知道它是什么了,但是当我需要看大量的地方或者在一个文件中查看的时候,这时候print就不大方便了,所 ...

  8. centos下python的pymssql模块安装及简单使用

    1.安装pymssq模块 1-1.环境准备: 1-1-1.unixODBC安装 yum install unixODBC unixODBC-devel -y 1-1-2.freetds安装 下载 fr ...

  9. python 利用tkinter模块设计出window窗口(搞笑版)

    代码如下 from tkinter import * import tkinter from tkinter import messagebox #定义了一个函数,当关闭window窗口时将会弹出一个 ...

随机推荐

  1. 调整文本输入框placeholder的颜色等样式

    input::-webkit-input-placeholder{     color: white !important;}input:-moz-placeholder{    color: whi ...

  2. tomcat:tomcat的OutOfMemoryError解决

    最近在熟悉一个开发了有几年的项目,需要把数据库从mysql移植到oracle,首先把jdbc的连接指向 mysql,打包放到tomcat里面,可以跑起来,没有问题,可是当把jdbc连接指向oracle ...

  3. php windows rename 中文出错

    php windows rename 中文出错 rename()函数可以重命名文件.目录等,但是要注意目的地和起始地址的编码. 比如:我的PHP文件编码是UTF-8,但是在WINDOW系统中中文默认编 ...

  4. Ubuntu下hadoop集群搭建

    --修改IP地址(克隆镜像后可修改可不修改) http://jingyan.baidu.com/article/e5c39bf5bbe0e739d7603396.html -------------- ...

  5. openstack中region、az、host aggregate、cell 概念

    1. region 更像是一个地理上的概念,每个region有自己独立的endpoint,regions之间完全隔离,但是多个regions之间共享同一个keystone和dashboard.(注:目 ...

  6. LBP简单实现

    Local Binary Pattern 确实够简单...先写个代码在这儿,空了再弄 #include <opencv2/opencv.hpp> #include <iostream ...

  7. GitLab版本管理【转】

    转自:http://www.cnblogs.com/wintersun/p/3930900.html GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目 ...

  8. 开源的zip_unzip库

    zip/unzip源码交叉编译 http://blog.chinaunix.net/uid-20288609-id-10016.html zlib 1.2.11 http://www.zlib.net ...

  9. animation动画的笔记

    animation的主要语法: -webkit-animation-duration:/*-webkit是针对个别浏览器内核支持,duration是动画时间*/ -webkit-animation-t ...

  10. python变现实现新浪微博登陆

    新浪微博的登陆现在是越来越那个了,以前的模拟浏览器登陆新浪微博貌似也越来不管用了 登陆信息由以前的form变成了现在javascript,javascript的加载居然用了一个javascript的函 ...