Canvas 画布

import tkinter as tk

window = tk.Tk()
window.title("daxiangcai's title")
window.geometry('800x400')

canvas = tk.Canvas(window, bg='green', height=100, width=200)
imagefile = tk.PhotoImage(file='')
image = canvas.create_image(10, 10, anchor='nw', image=imagefile)  # anchor代表放在坐标处的图片上的点,此处为nw(north west)
x0, y0, x1, y1 = 50, 50, 80, 80
line = canvas.create_line(x0, y0, x1, y1)
oval = canvas.create_oval(x0, y0, x1, y1, fill='red')
arc = canvas.create_arc(x0, y0, x1, y1, start=0, extend=180)
rect = canvas.create_rectangle(100, 30, 100+20, 30+20)


def move():
    canvas.move(rect, 0.2)  # 移动长方形
    

canvas.pack()

window.mainloop()

 

posted @ 2022-07-05 21:42  树叶本子  阅读(28)  评论(0)    收藏  举报