Tkinter画布-Canvas
2023-09-10 10:55:09
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()
这将产生以下结果:
最新文章
- JS中的this对象详解
- mongo(四)索引
- (笔记)Linux内核学习(九)之内核内存管理方式
- 从Apache Storm学到的经验教训 —— storm的由来(转)
- bzoj 1791: [Ioi2008]Island 岛屿
- AS:加载新版本的SWF文件。
- 移动开发之meta篇
- 我踩过的Alwayson的坑!(上集)
- Visual C++ 打印编程技术-编程基础-映射模式
- bzoj 1902: Zju2116 Christopher lucas定理 &;&; 数位DP
- The Better Way to Debug Your JavaScript Program
- CentOS添加swap分区
- http keepalive and tcpkeepalive
- sphinx2.8.8的配置文件
- 查找List中的最大最小值
- 微信浏览器的页面在PC端访问
- [LeetCode] Open the Lock 开锁
- sprintf格式化字符串带来的注入隐患
- PID控制器开发笔记之十三:单神经元PID控制器的实现
- Mac 远程连接 Windows
热门文章
- opencv 图像增强
- python全局替换文件内容脚本第1版
- windows 10 安装 sql 2005 安装失败
- Android编程 高德地图 中如何重写 定位按键 的触发事件 (com.amap.api.maps2d.LocationSource)点击定位后不仅定位在地图中心点上而且可以设置地图的缩放大小和提示
- 掌握Git撤销操作,随心所欲控制文件状态
- smvc配置属性编辑器:
- Windows2012启动自动帐户登陆
- Mysql按照字段值做分组行转列查询
- selenium-java,cookie登陆
- stm32寄存器版学习笔记03 外部中断