ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
| Tkinter画布 | | | --- | --- | | from Tkinter import * | 加载模块 | | canvas = Canvas(master, option=value, ...) | 创建画布,master: 按钮的父容器,option为可选参数 | ``` * 参数 * [canvas = Canvas(master, option=value, ...)] [option参数介绍] * @param [bd = 2] [边框宽度,单位像素,默认为 2 像素] * @param [bg = #ccc] [背景色] * @param [confine = true] [如果为 true (默认), 画布不能滚动到可滑动的区域外] * @param [cursor = arrow] [光标的形状设定,如arrow, circle, cross, plus 等] * @param [height = 200] [高度] * @param [highlightcolor = $fdfdfd] [要高亮的颜色] * @param [relief = FLAT] [边框样式,可选值为 FLAT、SUNKEN、RAISED、GROOVE、RIDGE。 默认为 FLAT] * @param [scrollregion = (w, n, e, s)] [一个元组 tuple (w, n, e, s) ,定义了画布可滚动的最大区域,w 为左边,n 为头部,e 为右边,s 为底部] * @param [width = 200] [画布在 X 坐标轴上的大小] * @param [xscrollincrement = 1] [用于滚动请求水平滚动的数量值] * @param [xscrollcommand] [ 水平滚动条,如果画布是可滚动的,则该属性是水平滚动条的 .set()方法] * @param [yscrollincrement] [类似 xscrollincrement, 但是垂直方向] * @param [yscrollcommand] [垂直滚动条,如果画布是可滚动的,则该属性是垂直滚动条的 .set()方法] * @return [创建一个画布] ``` ``` 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) ```