Skip to content

I am self teaching Python (slowly!) and have built a basic paint program where the brush 'colour' can be changed and that is about it... The click boxes can be drawn over though and wanted to see if it was possible to make this an area where it cannot be drawn on? I am also looking to have extra options in such as changing 'brush' size and shape…

rjbattye91/Self-Teaching---Paint

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Self-Teaching---Paint

I am self teaching Python (slowly!) and have built a basic paint program where the brush 'colour' can be changed and that is about it... The click boxes can be drawn over though and wanted to see if it was possible to make this an area where it cannot be drawn on? I am also looking to have extra options in such as changing 'brush' size and shape insert so any hints and tips on this would be appreciated!

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, lastY lastX = event.x lastY = event.y def on_click(event): store_position(event) def on_drag(event): canvas.create_line(lastX, lastY, event.x, event.y, fill = colour, width = 3) store_position(event) canvas.bind("", on_click) canvas.bind("", on_drag) red_id = canvas.create_rectangle(10, 10, 30, 30, fill = "red") blue_id = canvas.create_rectangle(10, 35, 30, 55, fill = "blue") black_id = canvas.create_rectangle(10, 60, 30, 80, fill = "black") white_id = canvas.create_rectangle(10, 85, 30, 105, fill = "white") cyan_id = canvas.create_rectangle(10, 110, 30, 130, fill = "cyan") yellow_id = canvas.create_rectangle(10, 135, 30, 155, fill = "yellow") green_id = canvas.create_rectangle(10, 160, 30, 180, fill = "green") def set_colour_red(event): global colour colour = "red" def set_colour_blue(event): global colour colour = "blue" def set_colour_black(event): global colour colour = "black" def set_colour_white(event): global colour colour = "white" def set_colour_cyan(event): global colour colour = "cyan" def set_colour_yellow(event): global colour colour = "yellow" def set_colour_green(event): global colour colour = "green" canvas.tag_bind(red_id, "", set_colour_red) canvas.tag_bind(blue_id, "", set_colour_blue) canvas.tag_bind(black_id, "", set_colour_black) canvas.tag_bind(white_id, "", set_colour_white) canvas.tag_bind(cyan_id, "", set_colour_cyan) canvas.tag_bind(yellow_id, "", set_colour_yellow) canvas.tag_bind(green_id, "", set_colour_green) window.mainloop()

About

I am self teaching Python (slowly!) and have built a basic paint program where the brush 'colour' can be changed and that is about it... The click boxes can be drawn over though and wanted to see if it was possible to make this an area where it cannot be drawn on? I am also looking to have extra options in such as changing 'brush' size and shape…

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages