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()

这将产生以下结果:

 

最新文章

  1. C#搜索指定文件夹内的符合要求的文件
  2. Swift安装
  3. 洛谷 P1379 八数码难题 Label:判重&&bfs
  4. Mssql链接mysql数据库
  5. 【CodeForces 312B】BUPT 2015 newbie practice #3A Archer
  6. php 采用fpdf乱码问题
  7. Strider-test 相关配置
  8. TCP 滑动窗口和 拥塞窗口
  9. 【转】出現 "PowerCam player support IE browser only!" 的錯誤訊息
  10. 3.MVC框架开发(Razor内嵌函数)
  11. HDU 5624 KK's Reconstruction
  12. ActiveMQ (三)—持久化消息
  13. Java入门(一):Hello World !
  14. JDBC-DBCP
  15. LeetCode题解之 Find Mode in Binary Search Tree
  16. Java包装类及其拆箱装箱
  17. 算法笔记 #007# Backtracking
  18. linux基础(2)-基础命令和基础特性
  19. Android DecorView浅析
  20. UVA 10177 Sqr/Rects/Cubes/Boxes?

热门文章

  1. IPv4地址范围和一些小知识
  2. Docker及常用操作
  3. [转载][QT][SQL]sql学习记录3_sqlite之update delete like
  4. cocos2d-x 3.17 jsb android运行报错
  5. 一个MySql Sql 优化技巧分享
  6. 每天一个linux命令(权限):【转载】 /etc/group文件详解
  7. BZOJ3926 Zjoi2015 诸神眷顾的幻想乡【广义后缀自动机】
  8. BZOJ4552 Tjoi2016&Heoi2016排序 【二分+线段树】*
  9. Http中Get/Post请求区别
  10. Sprint第一个冲刺(第四天)