代码如下:

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. POJ 2456 Aggressive cows---二分搜索法

    ///3.最大化最小值 /** POJ 2456 Aggressive cows Q:一排牛舍有N (2 <= N <= 100,000) 个,位置为x1,...,xN (0 <= ...

  2. python面向对象进阶(上)

    一 .isinstance(obj,cls)和issubclass(sub,super) (1)isinstance(obj,cls)检查对象obj是否是类 cls 的对象,返回True和Flase ...

  3. swift 之嵌套的理解 func chooseStepFunction(backwards: Bool) -> (Int) -> Int

    http://blog.csdn.net/lzx_322/article/details/28861199 swift 函数使用前面需要添加 func 有返回值需要使用-> 后面添加返回类型 , ...

  4. Shell Script Basics

    https://developer.apple.com/library/mac/documentation/OpenSource/Conceptual/ShellScripting/shell_scr ...

  5. 常见的makefile写法【转】

    转自:http://blog.csdn.net/ghostyu/article/details/7755177 版权声明:本文为博主原创文章,未经博主允许不得转载. .目标名称,摆脱手动设置目标名称 ...

  6. linux下源码安装netcat

    linux下源码安装netcat http://blog.chinaunix.net/uid-20783755-id-4211230.html 1,下载netcat源码,netcat-0.7.1-13 ...

  7. springboot 整合springDataJPA

    springboot 整合springDataJPA 〇.搭建springboot环境 一.添加依赖 mysql <!-- mysql驱动 --> <dependency> & ...

  8. 【 Linux】脚本导入格式

    在从windows文本(*.txt)格式导入到Linux中时,需要注意. 如果是直接将*.txt 导入到Linux系统,然后重命名使用会有问题,建议在linux系统中创建文件,然后直接复制内容到lin ...

  9. Selenium 多窗口元素定位处理

    以下文章来自于  上海-悠悠的博客 <Selenium2+python自动化13-多窗口.句柄(handle)> 有些页面的链接打开后,会重新打开一个窗口,对于这种情况,想在新页面上操作, ...

  10. python中的三元表达式

    if B = True: return A else: return C 用三元表达式可以写成: return A if B else C