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 | |
| parent | 70af2d6ecf3323874bac8c7e7e90a2ae68188824 (diff) | |
| download | presentations-a5fdf514ed77acd1ae4bf1c3442d750a921d8735.tar.gz presentations-a5fdf514ed77acd1ae4bf1c3442d750a921d8735.zip | |
Added PyOhio2012 presentation source code
Diffstat (limited to 'pyohio2012/src')
| -rw-r--r-- | pyohio2012/src/all_widgets.py | 53 | ||||
| -rw-r--r-- | pyohio2012/src/canvas.py | 29 | ||||
| -rw-r--r-- | pyohio2012/src/canvas_with_mouse.py | 43 | ||||
| -rw-r--r-- | pyohio2012/src/notebook.py | 36 | ||||
| -rw-r--r-- | pyohio2012/src/treeview.py | 60 | ||||
| -rw-r--r-- | pyohio2012/src/ttk_widgets.py | 43 | ||||
| -rw-r--r-- | pyohio2012/src/without_ttk.py | 39 |
7 files changed, 303 insertions, 0 deletions
diff --git a/pyohio2012/src/all_widgets.py b/pyohio2012/src/all_widgets.py new file mode 100644 index 0000000..a406a52 --- /dev/null +++ b/pyohio2012/src/all_widgets.py @@ -0,0 +1,53 @@ +from Tkinter import * + +class AllWidgets(): + def __init__(self, root): + + self.frame = Frame(root) + + self.build_window() + + self.frame.pack() + + menubar = Menu(root) + root['menu'] = menubar + + menu_file = Menu(menubar) + menu_file.add_command(label="Quit", command=self.quit) + + menubar.add_cascade(menu=menu_file, label='File') + + + def build_window(self): + Label(self.frame, text="Label").pack(side=TOP) + Button(self.frame, text="Button").pack(side=TOP) + + Entry(self.frame, text="Entry").pack(side=TOP) + lb = Listbox(self.frame, height=3) + lb.pack(side=TOP) + for x in ('Listbox 1', 'Listbox 2', 'Listbox 3'): + lb.insert('end', x) + #RadioButton(self.frame, text="Radio Button").pack(side=TOP) + LabelFrame(self.frame, text="Label Frame").pack(side=TOP) + Scale(self.frame, from_=0, to=200, orient=HORIZONTAL).pack(side=TOP) + Scrollbar(self.frame, orient=HORIZONTAL).pack(side=TOP, fill=X) + Spinbox(self.frame, from_=0, to=200).pack(side=TOP) + p = PhotoImage(file="image.gif") + l=Label(self.frame, image=p) + l.image = p + l.pack(side=TOP) + + t = Text(self.frame, height=5, width=20) + t.pack(side=TOP) + t.insert(END, "An editable\ntext widget") + + + def quit(self): + self.frame.quit() + +if __name__ == '__main__': + root = Tk() + + app = AllWidgets(root) + + root.mainloop() diff --git a/pyohio2012/src/canvas.py b/pyohio2012/src/canvas.py new file mode 100644 index 0000000..54b4c72 --- /dev/null +++ b/pyohio2012/src/canvas.py @@ -0,0 +1,29 @@ +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) + + 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.pack(fill=BOTH, expand=True) + + 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 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 diff --git a/pyohio2012/src/notebook.py b/pyohio2012/src/notebook.py new file mode 100644 index 0000000..326d0c7 --- /dev/null +++ b/pyohio2012/src/notebook.py @@ -0,0 +1,36 @@ +from tkinter import * +from tkinter.ttk import * + +class TkNotebook(): + def __init__(self, root): + + self.frame = Frame(root) + self.notebook = Notebook(self.frame) + + f1 = Frame(self.notebook, width=200, height=100) + f2 = Frame(self.notebook, width=200, height=100) + self.notebook.add(f1, text="Page 1") + self.notebook.add(f2, text="Page 2") + + self.label = Label(self.frame, text="A Notebook on the left") + + # Layout + self.frame.grid(row=0, column=0, sticky=(N, S, E, W)) + self.notebook.grid(row=0, column=0, sticky=(N, S, E, W)) + self.label.grid(row=0, column=1, sticky=(E,)) + + # Resize rules + root.columnconfigure(0, weight=1) + root.rowconfigure(0, weight=1) + self.frame.columnconfigure(0, weight=2) + self.frame.rowconfigure(0, weight=2) + + def quit(self): + self.frame.quit() + +if __name__ == '__main__': + root = Tk() + + app = TkNotebook(root) + + root.mainloop()
\ No newline at end of file diff --git a/pyohio2012/src/treeview.py b/pyohio2012/src/treeview.py new file mode 100644 index 0000000..b545245 --- /dev/null +++ b/pyohio2012/src/treeview.py @@ -0,0 +1,60 @@ +from tkinter import * +from tkinter.ttk import * + +class TkTrees(): + def __init__(self, root): + self.root = root + + self.notebook = Notebook(root) + + f1 = Frame(self.notebook) + f2 = Frame(self.notebook) + self.notebook.add(f1, text="Columned List") + self.notebook.add(f2, text="Tree") + + self.column_treeview(f1) + self.tree_treeview(f2) + + # Layout + self.notebook.grid(row=0, column=0, sticky=(N, S, E, W)) + + # Resize rules + root.columnconfigure(0, weight=1) + root.rowconfigure(0, weight=1) + + def column_treeview(self, parent): + + columns = ('Name', 'Description') + + self.ctree = Treeview(parent, columns=columns, show="headings") + for col in columns: + self.ctree.column(col, width=90) + self.ctree.heading(col, text=col) + + self.ctree.insert('', 'end', values=('Example', 'One row...')) + self.ctree.insert('', 'end', values=('Example Part 2', 'Another row...')) + + self.ctree.pack(fill=BOTH, expand=1) + + def tree_treeview(self, parent): + + self.ttree = Treeview(parent) + + id = self.ttree.insert('', 'end', text='Example') + self.ttree.insert(id, 'end', text='First sub item') + + id = self.ttree.insert('', 'end', text='Example Part 2') + self.ttree.insert(id, 'end', text='A different sub item') + + self.ttree.pack(fill=BOTH, expand=1) + + + def quit(self): + self.root.quit() + +if __name__ == '__main__': + root = Tk() + + app = TkTrees(root) + + root.mainloop()
\ No newline at end of file diff --git a/pyohio2012/src/ttk_widgets.py b/pyohio2012/src/ttk_widgets.py new file mode 100644 index 0000000..0aad592 --- /dev/null +++ b/pyohio2012/src/ttk_widgets.py @@ -0,0 +1,43 @@ +try: + from Tkinter import * + from ttk import * +except ImportError: + from tkinter import * + from tkinter.ttk import * + +class TtkWidgets(): + def __init__(self, root): + + self.frame = Frame(root) + + self.build_window() + + self.frame.pack() + + menubar = Menu(root) + root['menu'] = menubar + + menu_file = Menu(menubar) + menu_file.add_command(label="Quit", command=self.quit) + + menubar.add_cascade(menu=menu_file, label='File') + + def build_window(self): + cbv = StringVar() + Combobox(self.frame, textvariable=cbv, + values=('Canada', 'Sweden', 'Germany')).pack(side=TOP) + + Checkbutton(self.frame, text='Check').pack(side=TOP) + Radiobutton(self.frame, text='Radio').pack(side=TOP) + pb = Progressbar(self.frame, orient=HORIZONTAL, length=200, mode='indeterminate') + pb.start() + + def quit(self): + self.frame.quit() + +if __name__ == '__main__': + root = Tk() + + app = TtkWidgets(root) + + root.mainloop() diff --git a/pyohio2012/src/without_ttk.py b/pyohio2012/src/without_ttk.py new file mode 100644 index 0000000..b5da854 --- /dev/null +++ b/pyohio2012/src/without_ttk.py @@ -0,0 +1,39 @@ +from Tkinter import * + +class WithoutTtk(): + def __init__(self, root): + + self.frame = Frame(root) + + self.build_window() + + self.frame.pack(fill=BOTH) + + menubar = Menu(root) + root['menu'] = menubar + + menu_file = Menu(menubar) + menu_file.add_command(label="Quit", command=self.quit) + + menubar.add_cascade(menu=menu_file, label='File') + + + def build_window(self): + label = Label(self.frame, text="How do I look?") + label.pack(side=TOP) + + button_bad = Button(self.frame, text="Terrible", command=self.quit) + button_bad.pack(side=LEFT) + + button_good = Button(self.frame, text="Not too shabby", command=self.quit) + button_good.pack(side=RIGHT) + + def quit(self): + self.frame.quit() + +if __name__ == '__main__': + root = Tk() + + app = WithoutTtk(root) + + root.mainloop() |
