diff options
| author | unknown <Jeff@Spartan.(none)> | 2012-07-28 11:34:24 -0400 |
|---|---|---|
| committer | unknown <Jeff@Spartan.(none)> | 2012-07-28 11:34:24 -0400 |
| commit | a5fdf514ed77acd1ae4bf1c3442d750a921d8735 (patch) | |
| tree | 393d78f6a90400de74cae6831dcb287549cf99e8 /pyohio2012/src/canvas_with_mouse.py | |
| parent | 70af2d6ecf3323874bac8c7e7e90a2ae68188824 (diff) | |
| download | presentations-a5fdf514ed77acd1ae4bf1c3442d750a921d8735.tar.gz presentations-a5fdf514ed77acd1ae4bf1c3442d750a921d8735.zip | |
Added PyOhio2012 presentation source code
Diffstat (limited to 'pyohio2012/src/canvas_with_mouse.py')
| -rw-r--r-- | pyohio2012/src/canvas_with_mouse.py | 43 |
1 files changed, 43 insertions, 0 deletions
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("<Button-1>", self.start_line) + self.canvas.bind("<B1-Motion>", 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 |
