Tkinter——⑦canvas(画布)

Tkinter——canvas(画布)

python入门常用操作:https://blog.csdn.net/qq_33302004/article/details/112859327

 

import tkinter as tk

window = tk.Tk()
window.title('canvas')
window.geometry('1400x800')

canvas = tk.Canvas(window, bg='blue', height=500, width=1400)

# 1. 加载图片
# anchor 锚定示例:
# -----------------------
# | NW      N       NE  |
# |                     |
# | W    CENTER     E   |
# |                     |
# | SW      N       SE  |
# -----------------------
# 给予不同的anchor参数,是指图片的不同位置与0,0 对齐(例子中给的是0,0)
image_file = tk.PhotoImage(file = 'anim.gif')
image = canvas.create_image(0,0, anchor='nw', image=image_file)

# 2.画线
x0, y0, x1, y1 = 50, 50, 200, 200
line = canvas.create_line(x0, y0, x1, y1, fill='red',width=5)

# 3.画圆,这里的x0, y0, x1, y1 是指外切正方形
oval = canvas.create_oval(x0, y0, x1, y1, fill='green')

# 4.扇形,用 start=0, extent=120 指定扇形的角度范围
arc = canvas.create_arc(x0+100, y0+100, x1+100, y1+100, start=0, extent=120, fill='pink')

# 5.矩形
rect = canvas.create_rectangle(x0+200, y0+200, x1+200, y1+200,fill='yellow')

canvas.pack()

def move_it():
    # 移动canvas中的元素
    canvas.move(rect,10,-10)
    return
button = tk.Button(window, text='move', command=move_it, font = ('Helvetica', 16)).pack()

window.mainloop()

效果:

Tkinter——⑦canvas(画布)_第1张图片

你可能感兴趣的:(python,tkinter,canvas,python,window,move)