Skip to content

Commit 4b64ded

Browse files
committed
Added Painting Tool in GUIScripts
1 parent 8ddf528 commit 4b64ded

File tree

10 files changed

+173
-0
lines changed

10 files changed

+173
-0
lines changed

Diff for: GUIScripts/Painting Tool/Images/1.jpg

46.4 KB
Loading

Diff for: GUIScripts/Painting Tool/Images/2.jpg

61.2 KB
Loading

Diff for: GUIScripts/Painting Tool/Images/3.jpg

78.2 KB
Loading

Diff for: GUIScripts/Painting Tool/Images/4.jpg

82.4 KB
Loading

Diff for: GUIScripts/Painting Tool/Images/5.jpg

102 KB
Loading

Diff for: GUIScripts/Painting Tool/Images/6.jpg

104 KB
Loading

Diff for: GUIScripts/Painting Tool/Images/sample_video.gif

8.33 MB
Loading

Diff for: GUIScripts/Painting Tool/README.md

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# ✔ PAINTING TOOL
2+
- ### A Painitng Tool is an simple paint application created in python with tkinter gui.
3+
- ### In this application user will be given a drawing area along with button like PEN, BRUSH, COLOUR, ERASER and EXIT.
4+
- ### Using PEN button, user can select the pen and start drawing or writing a freehand design.
5+
- ### Using BRUSH button, user can select brush and start drawing.
6+
- ### User can also select the colour of his/her choices and also can erase after drawing.
7+
- ### Also user can change the width of PEN, using scale which is provided of length 10, and user can set any width of PEN from 1 to 10.
8+
9+
10+
****
11+
12+
# REQUIREMENTS :
13+
- ### python 3
14+
- ### tkinter module
15+
- ### from tkinter messagebox module
16+
- ### from tkinter.colorchooser import askcolor
17+
18+
****
19+
20+
# How this Script works :
21+
- ### User just need to download the file and run the painting_tool.py on their local system.
22+
- ### Now on the main window of the application, there will be different button and a drawing area below it.
23+
- ### User first need to select the PEN, inorder to draw anything on the drawing area.
24+
- ### By default the width of PEN will be 1, and user can chenge it using scale provided to him(from 1 to 10).
25+
- ### Also the colour of PEN will be black by default, which user can change using the COLOUR button.
26+
- ### Clicking on the colour a pop up window of many colour will open, and user can choose any one and click on OK.
27+
- ### Also there is choice to user to draw using brush, which user can get using BRUSH button.
28+
- ### Also there is an exit button, clicking on which exit dialog box appears asking for the permission of the user for closing the window.
29+
30+
# Purpose :
31+
- ### This scripts helps us to draw any free-handed design of any width, any colour and can erase also.
32+
33+
# Compilation Steps :
34+
- ### Install tkinter, python3
35+
- ### After that download the code file, and run painting_tool.py on local system.
36+
- ### Then the script will start running and user can explore and play with it by drawing any free-handed design.
37+
38+
****
39+
40+
# SCREENSHOTS :
41+
42+
****
43+
44+
<p align="center">
45+
<img width = 1000 src="Images/1.jpg" /><br>
46+
<img width = 1000 src="Images/2.jpg" /><br>
47+
<img width = 1000 src="Images/3.jpg" /><br>
48+
<img width = 1000 src="Images/4.jpg" /><br>
49+
<img width = 1000 src="Images/5.jpg" /><br>
50+
<img width = 1000 src="Images/6.jpg" /><br>
51+
</p>
52+
53+
****
54+
55+
# Below is the link to sample video of how this painting tool works :
56+
<p align="center">
57+
<img src="Images/sample_video.gif" /><br>
58+
</p>
59+
60+
# Name :
61+
- ### Akash Ramanand Rajak
62+

Diff for: GUIScripts/Painting Tool/painting_tool.py

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
2+
# Painting Tool
3+
4+
# imported necessary library
5+
from tkinter import *
6+
from tkinter.colorchooser import askcolor
7+
from tkinter import messagebox
8+
import tkinter.messagebox as mbox
9+
10+
# created a class for paint
11+
class Paint(object):
12+
13+
DEFAULT_PEN_SIZE = 5.0
14+
DEFAULT_COLOR = 'black'
15+
16+
# init method defined
17+
def __init__(self):
18+
self.root = Tk()
19+
20+
# button created for PEN
21+
self.pen_button = Button(self.root, text='PEN', command=self.use_pen,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
22+
self.pen_button.grid(row=0, column=0)
23+
24+
# button created for BRUSH
25+
self.brush_button = Button(self.root, text='BRUSH', command=self.use_brush,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
26+
self.brush_button.grid(row=0, column=1)
27+
28+
# button created for COLOR
29+
self.color_button = Button(self.root, text='COLOR', command=self.choose_color,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
30+
self.color_button.grid(row=0, column=2)
31+
32+
# button created for ERASER
33+
self.eraser_button = Button(self.root, text='ERASER', command=self.use_eraser,font=("Arial", 20), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
34+
self.eraser_button.grid(row=0, column=3)
35+
36+
# created a scale from 1 to 10
37+
self.choose_size_button = Scale(self.root, from_=1, to=10, orient=HORIZONTAL,width = 20,font=("Arial", 20), bg = "yellow", fg = "blue", borderwidth=3)
38+
self.choose_size_button.grid(row=0, column=4)
39+
40+
# button created for EXIT
41+
self.exit_button = Button(self.root, text='EXIT', command=self.exit_win, font=("Arial", 20),bg="red", fg="blue", borderwidth=3, relief="raised")
42+
self.exit_button.grid(row=0, column=5)
43+
44+
# created a drawing area
45+
self.c = Canvas(self.root, bg='white', width=1000, height=600)
46+
self.c.grid(row=1, columnspan=7)
47+
48+
self.root.title("Painting Tool")
49+
self.setup()
50+
self.root.mainloop()
51+
52+
# function for exiting
53+
def exit_win(self):
54+
if mbox.askokcancel("Exit", "Do you want to exit?"):
55+
self.root.destroy()
56+
57+
# function to setup all things
58+
def setup(self):
59+
self.old_x = None
60+
self.old_y = None
61+
self.line_width = self.choose_size_button.get()
62+
self.color = self.DEFAULT_COLOR
63+
self.eraser_on = False
64+
self.active_button = self.pen_button
65+
self.c.bind('<B1-Motion>', self.paint)
66+
self.c.bind('<ButtonRelease-1>', self.reset)
67+
68+
# function for pen
69+
def use_pen(self):
70+
self.activate_button(self.pen_button)
71+
72+
# function for brush
73+
def use_brush(self):
74+
self.activate_button(self.brush_button)
75+
76+
# function for choosing colour
77+
def choose_color(self):
78+
self.eraser_on = False
79+
self.color = askcolor(color=self.color)[1]
80+
81+
# function for eraser
82+
def use_eraser(self):
83+
self.activate_button(self.eraser_button, eraser_mode=True)
84+
85+
def activate_button(self, some_button, eraser_mode=False):
86+
self.active_button.config(relief=RAISED)
87+
some_button.config(relief=SUNKEN)
88+
self.active_button = some_button
89+
self.eraser_on = eraser_mode
90+
91+
# function for painting
92+
def paint(self, event):
93+
self.line_width = self.choose_size_button.get()
94+
paint_color = 'white' if self.eraser_on else self.color
95+
if self.old_x and self.old_y:
96+
self.c.create_line(self.old_x, self.old_y, event.x, event.y,
97+
width=self.line_width, fill=paint_color,
98+
capstyle=ROUND, smooth=TRUE, splinesteps=36)
99+
self.old_x = event.x
100+
self.old_y = event.y
101+
102+
def reset(self, event):
103+
self.old_x, self.old_y = None, None
104+
105+
106+
# main funtion
107+
if __name__ == '__main__':
108+
Paint()

Diff for: GUIScripts/Painting Tool/requirements.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
libraries used : tkinter
2+
messagebox
3+
from tkinter.colorchooser import askcolor

0 commit comments

Comments
 (0)