1. 程式人生 > >pythonGUI編程用Canvas模擬畫板

pythonGUI編程用Canvas模擬畫板

idt paint create -1 tkinter png height width ges

代碼如下:

from tkinter import *
import webbrowser

root = Tk()

w = Canvas(root,width=400,height=200)

w.pack()

def paint(event):
    x1,y1 = (event.x-1),(event.y-1)
    x2,y2 = (event.x+1),(event.y+1)
    w.create_oval(x1,y1,x2,y2,fill="red")
w.bind("<B1-Motion>",paint)

Label(root,text="使用鼠標左鍵開始畫圖
").pack(side=BOTTOM) mainloop()

運行截圖:

技術分享

pythonGUI編程用Canvas模擬畫板