Python - Tkinter画布-Canvas: Canvas是一个长方形的面积,图画或其他复杂的布局。可以放置在画布上的图形,文字,部件,或是帧
Canvas是一个长方形的面积,图画或其他复杂的布局。可以放置在画布上的图形,文字,部件,或是帧.

语法:

这里是一个简单的语法来创建这个widget:

 w = Canvas ( master, option=value, ... )

参数:

  • master:  这代表了父窗口.

  • options: 下面是这个小工具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.

Option Description
bd Border width in pixels. Default is 2.
bg Normal background color.
confine If true (the default), the canvas cannot be scrolled outside of the scrollregion.
cursor Cursor used in the canvas like arrow, circle, dot etc.
height Size of the canvas in the Y dimension.
highlightcolor Color shown in the focus highlight.
relief Relief specifies the type of the border. Some of the values are SUNKEN, RAISED, GROOVE, and RIDGE.
scrollregion A tuple (w, n, e, s) that defines over how large an area the canvas can be scrolled, where w is the left side, n the top, e the right side, and s the bottom.
width Size of the canvas in the X dimension.
xscrollincrement If you set this option to some positive dimension, the canvas can be positioned only on multiples of that distance, and the value will be used for scrolling by scrolling units, such as when the user clicks on the arrows at the ends of a scrollbar.
xscrollcommand If the canvas is scrollable, this attribute should be the .set() method of the horizontal scrollbar.
yscrollincrement Works like xscrollincrement, but governs vertical movement.
yscrollcommand If the canvas is scrollable, this attribute should be the .set() method of the vertical scrollbar.

Canvas的widget可以支持以下标准的条目:

arc .创建弧项目,它可以是一个和弦,饼图扇区,或是一个简单的弧.

coord = 10, 50, 240, 210
arc = canvas.create_arc(coord, start=0, extent=150, fill="blue")

image . 创建一个图像的项目,它可以是位图图像或是照片图像类的一个实例.

filename = PhotoImage(file = "sunshine.gif")
image = canvas.create_image(50, 50, anchor=NE, image=filename)

line . 创建一条线条目.

line = canvas.create_line(x0, y0, x1, y1, ..., xn, yn, options)

oval . 在给定的坐标创建一个圆或椭圆。它的坐标两双。为椭圆的边界矩形左上角和底部右下角.

oval = canvas.create_oval(x0, y0, x1, y1, options)

polygon . 创建一个多边形的项目,必须有至少三个顶点.

oval = canvas.create_polygon(x0, y0, x1, y1,...xn, yn, options)

例子:

自行尝试下面的例子:

import Tkinter
import tkMessageBox top = Tkinter.Tk() C = Tkinter.Canvas(top, bg="blue", height=250, width=300) coord = 10, 50, 240, 210
arc = C.create_arc(coord, start=0, extent=150, fill="red") C.pack()
top.mainloop()

这将产生以下结果:

 

Tkinter画布-Canvas的更多相关文章

  1. pywin32获得tkinter的Canvas窗口句柄,并在上面绘图

    上一篇博文获得主窗口句柄使用的是root.frame或者通过子控件调用master.frame方法,但是子控件本身没有frame方法.那么怎么获得子控件的句柄呢?试过了很多办法,想过把Canvas当作 ...

  2. HTML 5 画布(canvas)

    canvas 元素使用 JavaScript 在网页上绘制图像,本身是没有绘图能力. canvas 是一个矩形区域,可以控制其每一像素. canvas 拥有多种绘制路径.矩形.圆形.字符以及添加图像的 ...

  3. HTML5画布Canvas

    一.Canvas概念介绍 1.概念 Canvas : 画布 2.作用 : HTML5 Canvas 元素用于图形的绘制, 通过脚本(通常是JavaScript)来完成.它本身只是个图形容器,必须使用脚 ...

  4. HTML5画布(CANVAS)速查简表

    HTML5画布(CANVAS)速查简表 http://www.webhek.com/misc/html5-canvas-cheat-sheet/

  5. PHP《将画布(canvas)图像保存成本地图片的方法》

    用PHP将网页上的Canvas图像保存到服务器上的方法 2014年6月27日 歪脖骇客 发表回复 8 在几年前HTML5还没有流行的时候,我们的项目经理曾经向我提出这样一个需求:让项目评审专家们在评审 ...

  6. 转载:将画布(canvas)图像保存成本地图片的方法

    之前我曾介绍过如何将HTML5画布(canvas)内容转变成图片形式,方法十分简单.但后来我发现只将canvas内容转变成图片输出还不够,如何能将转变后的图片保存到本地呢? 其实,这个方法也是非常简单 ...

  7. 面向画布(Canvas)的JavaScript库

    面向画布(Canvas)的JavaScript库 总结 每个库各有特色,根据需求选择   学习要点 面向画布(Canvas)的JavaScript库 EaselJS 是一个封装了 HTML5 画布(C ...

  8. 学习前端第二天心得体会(初步了解HTML5的部分API以及画布Canvas)

    一.HTML5部分API 1.选择器querySelector和querySelectorAll 1.1.querySelector:返回文档中匹配指定的CSS选择器的第一元素.  document. ...

  9. java 图形化小工具Abstract Window Toolit :画笔Graphics,画布Canvas(),弹球小游戏

    画笔Graphics Java中提供了Graphics类,他是一个抽象的画笔,可以在Canvas组件(画布)上绘制丰富多彩的几何图和位图. Graphics常用的画图方法如下: drawLine(): ...

随机推荐

  1. U盘传送容量与格式问题

    问题 今天想将7.6G的文件拷到U盘里,提示u盘内存不足,其实内存为14+G. 解答 U盘格式对于U盘的传送大小有限制 下面为U盘三种不同格式的应用及优缺点 FAT32格式:为系统默认格式,具有极佳的 ...

  2. elastic_search 指令

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ pass """ import os i ...

  3. IOS UIView 放大缩小

    /创建缩小了的视图myWeiBoImageVC = [[UIViewController alloc] init];myWeiBoImageVC.view.clipsToBounds = YES;my ...

  4. 【angularJS】启动(bootstrap)机制

    Angular的启动分为手动和自动两种. 自动启动 定义模块的例子中,采用的就是自动的方式:通过内置的指令ngApp 来指定启动时加载的模块.<html ng-app="myApp&q ...

  5. Cascalog了解

    Cascalog一种能使在Hadoop上使用Clojure处理数据变得简单直观的工具. Cascalog综合了两大顶尖技术:Clojure和Hadoop,同时让Datalog焕发青春. Cascalo ...

  6. spring cloud feign 接口继承以及参数传递的问题

    1. 优势     可以使用maven 进行访问,实现代码的共享,减少跨服务调用服务编写的问题   2. 使用      定义接口 publicinterfaceIUserService{ @Requ ...

  7. How to install cacti on centos 6

    Cacti – Network and performance monitoring tool   Cacti is one of best monitoring tool used to monit ...

  8. FastAdmin 如何查看 ICON 名字?

    FastAdmin 如何查看 ICON 名字? 群问题: [A货] ★^猪大胖-镇江 我想问问大家谁知道如何快速查找icon的name 每次我都要编辑权限那里去复制 [吐槽]孤狼-海口 2018/4/ ...

  9. python编程规范系列--建议08~18

    本系列来自<编写高质量代码 改善python程序的91个建议>的读书笔记整理.  本章主要内容 建议8:利用assert语句来发现问题 建议9:数据交换值时不推荐使用中间交换变量 建议10 ...

  10. getpwuid()

    getpwuid函数是通过用户的uid查找用户的passwd数据.如果出错时,它们都返回一个空指针并设置errno的值,用户可以根据perror函数查看出错的信息. 外文名 getpwuid() 头文 ...