我是自学教学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)