Tkinter(六)—— Canvas画布

  1. Canvas画布基础版本
# Canvas画布1,最基础版

import tkinter as tk

window = tk.Tk()
window.title('canvas 画布')
window.geometry('1000x500')

canvas = tk.Canvas(window,bg = 'white',height = 600,width = 400)
image1 = tk.PhotoImage(file = 'F:/Python/a1.png') #打开图片,但好像只能打开png格式的。
image = canvas.create_image(10,10,anchor = 'nw',image = image1) #将图片的西北角(左上角)固定在(10,10)这个位置上。
canvas.pack()

window.mainloop()

2 . 画布——增加形状

import tkinter as tk

window = tk.Tk()
window.title('Scale尺度')
window.geometry('1000x500')

canvas = tk.Canvas(window,bg = 'white',height = 600,width = 400)
canvas.pack()

# 导入图片
image1 = tk.PhotoImage(file = 'F:/Python/a1.png')
image = canvas.create_image(10,10,anchor = 'nw',image = image1)

# 导入其它形状
x0,y0,x1,y1 = 250,250,280,280
line = canvas.create_line(x0,y0,x1,y1) #直线
oval = canvas.create_oval(x0,y0,x1,y1,fill = 'red') #圆形
arc = canvas.create_arc(x0+30,y0+30,x1+30,y1+30,start = 0,extent = 120) #扇形,起止角度
rect = canvas.create_rectangle(20,20,200,200) #矩形

window.mainloop()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值