GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||
GeezerVison is showing www.runoob.com — Python Tkinter 画布(Canvas) | 菜鸟教程
Python 基础教程
Python 基础教程
Python 简介
Python 环境搭建
Python 中文编码
Python VS Code
Python 基础语法
Python 变量类型
Python 运算符
Python 条件语句
Python 循环语句
Python While 循环语句
Python for 循环语句
Python 循环嵌套
Python break 语句
Python continue 语句
Python pass 语句
Python Number(数字)
Python 字符串
Python 列表(List)
Python 元组
Python 字典(Dictionary)
Python 日期和时间
Python 函数
Python 模块
Python 文件I/O
Python File 方法
Python 异常处理
Python OS 文件/目录方法
Python 内置函数
Python 高级教程Python 面向对象 Python 正则表达式 Python CGI 编程 Python MySQL Python 网络编程 Python SMTP Python 多线程 Python XML 解析 Python GUI 编程(Tkinter) Python2.x 与 3.x 版本区别 Python IDE Python JSON Python AI 绘画 Python 100例 Python 测验Python Tkinter 画布(Canvas)Python Tkinter 画布(Canvas)组件和 html5 中的画布一样,都是用来绘图的。您可以将图形,文本,小部件或框架放置在画布上。 语法语法格式如下: w = Canvas ( master, option=value, ... )
Canvas 组件支持以下标准选项: 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) 实例实例中点击按钮会显示一个信息: 实例#!/usr/bin/python
# -*- coding: UTF-8 -*-
import Tkinter
import tkMessageBox
# -*- coding: cp936 -*-
# 创建一个矩形,指定画布的颜色为白色
from Tkinter import *
root = Tk()
# 创建一个Canvas,设置其背景色为白色
cv = Canvas(root,bg = 'white')
# 创建一个矩形,坐标为(10,10,110,110)
cv.create_rectangle(10,10,110,110)
cv.pack()
root.mainloop()
# 为明显起见,将背景色设置为白色,用以区别 root
top.mainloop()
测试输出结果如下:
AI 思考中...
| ||||||||||||||||||||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |