Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update paint.py #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Applications/Paint/paint.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class Paint(object):
def __init__(self):
self.root = Tk()

self.pen_button = Button(self.root, text = 'pen', command = self.use_pen)
self.pen_button.grid(row = 0, column = 0)
self.pen_button = Button(self.root, text='pen', command=self.use_pen)
self.pen_button.grid(row=0, column=0)

self.brush_button = Button(self.root, text = 'brush', command = self.use_brush)
self.brush_button = Button(self.root, text='brush', command=self.use_brush)
self.brush_button.grid(row=0, column=1)

self.color_button = Button(self.root, text='color', command=self.choose_color)
Expand All @@ -23,7 +23,7 @@ def __init__(self):
self.choose_size_button = Scale(self.root, from_=1, to=10, orient=HORIZONTAL)
self.choose_size_button.grid(row=0, column=4)

self.c=Canvas(self.root, bg='white', width=600, height=600)
self.c = Canvas(self.root, bg='white', width=600, height=600)
self.c.grid(row=1, columnspan=5)

self.setup()
Expand All @@ -36,7 +36,7 @@ def setup(self):
self.color = self.color
self.eraser_on = False
self.active_button = self.pen_button
self.c.bind('<B1-Motion>', self.print)
self.c.bind('<B1-Motion>', self.paint)
self.c.bind('<ButtonRelease-1>', self.reset)

def use_pen(self):
Expand All @@ -53,18 +53,18 @@ def use_eraser(self):
self.activate_button(self.eraser_button, eraser_mode=True)

def activate_button(self, some_button, eraser_mode=False):
self.activate_button.config(relief=RAISED)
self.active_button.config(relief=RAISED)
some_button.config(relief=SUNKEN)
self.active_button = some_button
self.eraser_on = eraser_mode

def print(self, event):
def paint(self, event):
self.line_width = self.choose_size_button.get()
paint_color = 'white' if self.eraser_on else self.color
if self.old_x and self.old_y:
self.c.create_line(self.old_x, self.old_y, event.x, event.y, width=self.line_width, fill=paint_color, capstyle=ROUND, smooth=TRUE, splinesteps=36)
self.old_x = event.x
self.old_y = event.y
self.old_x = event.x
self.old_y = event.y

def reset(self, event):
self.old_x, self.old_y = None, None
Expand Down