我是自學教學python(慢慢!),並且已經建立了一個基本的油漆程序,可以在其中更改刷子“顏色”,這就是……可以繪製單擊框,但想看看是否可以使它成為一個無法吸引它的區域?我還希望有額外的選擇,例如更改“刷子”尺寸和形狀插入物,以便對此表示讚賞!
import tkinter print("To draw, hold down the left mouse button and move the cursor.") print("To change the brush colour, click on one of the colours.") window = tkinter.Tk() canvas = tkinter.Canvas(window, width = 800, height = 600, bg = "white") canvas.pack() lastX, lastY = 0,0 colour = "black" def store_position(event): global lastX,last lastx = event.x last = event.y def on_click(event):store_position(event)def on_drag(event):canvas.create_line(lastx,lastx,lasty,event.x,event.x,event.y,fill = color,width = 3) canvas.create_rectangle(10,10,30,30,填充=“紅色”)blue_id = canvas.create_rectangle(10,35,30,55,fill =“ blue”) fill =“白色”)cyan_id = canvas.create_rectangle(10,110,30,130,fill =“ cyan”)yellow_id = canvas.create_rectangle(10,135,30,155,fill =“ fill =“ offer =“ yellow”) set_colour_red(event):全局顏色顏色=“ red” def set_colour_blue(event):全局顏色color =“ blue” def set_colour_black(event):全局顏色color =“ black” def set_colour_white(event):global color =“ def set_colour_cyan(event_cy_cyan(evens) “黃色” def set_colour_green(事件):全局顏色=“綠色” set_colour_white)canvas.tag_bind(cyan_id,“”,set_colour_cyan)canvas.tag_bind(yellow_id,“”,set_colour_yellow)