Tkinter画布-Canvas
2024-10-18 17:01:41
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()
这将产生以下结果:
最新文章
- [原]一个针对LVS的压力测试报告
- 微信小程序的机会在于重新理解群组与二维码
- JS:事件处理程序
- 用Python写爬虫爬取58同城二手交易数据
- HDU 2068 RPG的错排
- PHP5中魔术方法
- c#控制IE浏览器自动点击等事件WebBrowser,mshtml.IHTMLDocument2 .
- Javascript——Math对象
- JavaWeb学习记录(二十)——Model1模式(javaBean+jsp)实现简单计算器案例
- CS0016: 未能写入输出文件的解决方法
- [转]Oracle查询树形数据的叶节点和子节点
- POJ	2536 Gopher II
- Linux下I/O多路转接之select --fd_set
- 使Asp.net Core同时支持输出Json/Xml
- js 日期 相关
- 让openvpn自启动的命令笔记(windows)
- hdu3746 Cyclic Nacklace【nxt数组应用】【最小循环节】
- 大型运输行业实战_day10_1_自定义事务管理类
- 黄聪:C#程序中判断是否处在DEBUG调试状态或者RELEASE发布状态
- 【LeetCode 67_字符串_算术运算】Add Binary