Tkinter画布-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的更多相关文章
- pywin32获得tkinter的Canvas窗口句柄,并在上面绘图
上一篇博文获得主窗口句柄使用的是root.frame或者通过子控件调用master.frame方法,但是子控件本身没有frame方法.那么怎么获得子控件的句柄呢?试过了很多办法,想过把Canvas当作 ...
- HTML 5 画布(canvas)
canvas 元素使用 JavaScript 在网页上绘制图像,本身是没有绘图能力. canvas 是一个矩形区域,可以控制其每一像素. canvas 拥有多种绘制路径.矩形.圆形.字符以及添加图像的 ...
- HTML5画布Canvas
一.Canvas概念介绍 1.概念 Canvas : 画布 2.作用 : HTML5 Canvas 元素用于图形的绘制, 通过脚本(通常是JavaScript)来完成.它本身只是个图形容器,必须使用脚 ...
- HTML5画布(CANVAS)速查简表
HTML5画布(CANVAS)速查简表 http://www.webhek.com/misc/html5-canvas-cheat-sheet/
- PHP《将画布(canvas)图像保存成本地图片的方法》
用PHP将网页上的Canvas图像保存到服务器上的方法 2014年6月27日 歪脖骇客 发表回复 8 在几年前HTML5还没有流行的时候,我们的项目经理曾经向我提出这样一个需求:让项目评审专家们在评审 ...
- 转载:将画布(canvas)图像保存成本地图片的方法
之前我曾介绍过如何将HTML5画布(canvas)内容转变成图片形式,方法十分简单.但后来我发现只将canvas内容转变成图片输出还不够,如何能将转变后的图片保存到本地呢? 其实,这个方法也是非常简单 ...
- 面向画布(Canvas)的JavaScript库
面向画布(Canvas)的JavaScript库 总结 每个库各有特色,根据需求选择 学习要点 面向画布(Canvas)的JavaScript库 EaselJS 是一个封装了 HTML5 画布(C ...
- 学习前端第二天心得体会(初步了解HTML5的部分API以及画布Canvas)
一.HTML5部分API 1.选择器querySelector和querySelectorAll 1.1.querySelector:返回文档中匹配指定的CSS选择器的第一元素. document. ...
- java 图形化小工具Abstract Window Toolit :画笔Graphics,画布Canvas(),弹球小游戏
画笔Graphics Java中提供了Graphics类,他是一个抽象的画笔,可以在Canvas组件(画布)上绘制丰富多彩的几何图和位图. Graphics常用的画图方法如下: drawLine(): ...
随机推荐
- URL中不应出现汉字
浏览器会在跳转时,先将汉字编译成 Unicode,然后跳转,导致hash值改变两次,相当于history 中 加入了两次URL
- word-break:break-all 打散文字,强制对齐
- JSCover(查看代码覆盖率)
1. [文档](http://tntim96.github.io/JSCover/manual/manual.xml)1. [下载](https://sourceforge.net/projects/ ...
- 程序设计入门-C语言基础知识-翁恺-第七周:指针与字符串-详细笔记(七)
目录 第七周:指针与字符串 7.1 指针初步 7.2 字符类型 7.3 字符串 7.3 课后练习 第七周:指针与字符串 7.1 指针初步 sizeof 是一个运算符,给出某个类型或变量在内存中所占据的 ...
- vc 编译器的一些精典报错
本篇将平时遇到的一些编译错误 , 记录于此 , 同时帖上分析
- SGU495Kids and Prizes(数学期望||概率DP||公式)
495. Kids and Prizes Time limit per test: 0.25 second(s) Memory limit: 262144 kilobytes input: stand ...
- linux自学(四)之开始centos学习,网络配置
上一篇:linux自学(三)之开启虚拟机 安装好镜像之后,重启之后需要登录,我这里直接是root账号直接登录的,注意:输入密码的时候不显示. 之后输入ifconfig最常用的命令来查看网卡信息,出现c ...
- BZOJ2090: [Poi2010]Monotonicity 2【线段树优化DP】
BZOJ2090: [Poi2010]Monotonicity 2[线段树优化DP] Description 给出N个正整数a[1..N],再给出K个关系符号(>.<或=)s[1..k]. ...
- selenium python实例脚本1
#!/usr/local/bin/python3 # coding=utf-8 #统一编码from selenium import webdriverfrom time import sleep#im ...
- Java调用函数传递参数到底是值传递还是引用传递
今天翻看微信上有关Java技术的公众号时,看到了一篇关于Java中值传递的问题,文章讨论了在Java中调用函数进行传参的时候到底是值传递还是引用传递这个面试时会问到的问题.之前也接触过类似的问题,但只 ...