From a5fdf514ed77acd1ae4bf1c3442d750a921d8735 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 28 Jul 2012 11:34:24 -0400 Subject: Added PyOhio2012 presentation source code --- pyohio2012/src/canvas_with_mouse.py | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 pyohio2012/src/canvas_with_mouse.py (limited to 'pyohio2012/src/canvas_with_mouse.py') diff --git a/pyohio2012/src/canvas_with_mouse.py b/pyohio2012/src/canvas_with_mouse.py new file mode 100644 index 0000000..41eac41 --- /dev/null +++ b/pyohio2012/src/canvas_with_mouse.py @@ -0,0 +1,43 @@ +from tkinter import * +from tkinter.ttk import * + +class TkCanvas(): + def __init__(self, root): + + self.frame = Frame(root) + self.canvas = Canvas(self.frame) + self.canvas.grid(row=0, column=0, sticky=(N,S,E,W)) + + self.draw_rect() + + quit_button = Button(self.frame, text='Quit', command=self.quit) + quit_button.grid(row=1, column=0, sticky=(S,E)) + + self.frame.columnconfigure(0, weight=2) + self.frame.rowconfigure(0, weight=2) + + self.frame.pack(fill=BOTH, expand=True) + + self.canvas.bind("", self.start_line) + self.canvas.bind("", self.draw_line) + self.initial = (0,0) + + def start_line(self, event): + self.initial = (event.x, event.y) + + def draw_line(self, event): + self.canvas.create_line((self.initial[0], self.initial[1], event.x, event.y)) + self.initial = (event.x, event.y) + + def draw_rect(self): + self.canvas.create_rectangle((100,100), (30,40)) + + def quit(self): + self.frame.quit() + +if __name__ == '__main__': + root = Tk() + + app = TkCanvas(root) + + root.mainloop() \ No newline at end of file -- cgit v1.2.3