1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
title: An Introduction to Tkinter
subtitle: A User's Perspective
author: Jeffrey B. Armstrong
company: Approximatrix, LLC
footer: PyOhio
subfooter: 28 July 2012
h1. Introduction
* Tkinter (or tkinter)
** Interface to Tcl/Tk
** The only GUI framework in the Python standard library
** Simple to use
* The speaker
** Casual Tkinter user
** Some experience with other GUI toolkits
h1. Opinions
* Three types of people here
** Never used it
** Use it and Like it
** Hate it
h1. Why Care?
* Tkinter is part of the Python standard library
* Lightweight
* _Good enough_
** In fact, it can be great!
h1. The Past
* Limited widget set
* Unweildy _import_
* Considered ugly
h1. The Present
* Python 3.x
** Changed to Pythonic namespaces, like _tkinter_
** Introduced...
h1. Themed Tk
* `ttk` module
* Makes old Tkinter look pretty
** Kinda platform-specific...
h1. Getting Started
* Tk operates in "loop" that is transparent to the developer
* Widgets are assigned parents, which contain other widgets, etc.
* Layout managers handle widget placement
* Widgets can have events "bound" to them and respond accordingly
h1. Layout Managers
* Tkinter provides three geometry managers
** absolute (avoid this)
** pack
** grid
h1. pack Layout
* Extremely simple
* Specify a side
* Parent sizes itself to minimally fit everything
* Not particularly flexible for complex layouts
h1. grid Layout
* Closer to other toolkits
* Frames are laid out in a grid
** Resizing can be handled via _expand_ arguments
h1. Widgets
* tkinter historically provides common, simple widgets
* Considered a shortcoming
** Missing more advanced widgets
h1. Widgets
!{border:0px; float:right; height:14em}widgets.png!
<table style="width: 40%;">
<tr><td>Button</td><td>Menu</td></tr>
<tr><td>Frame</td><td>Scale</td></tr>
<tr><td>Label</td><td>Scrollbar</td></tr>
<tr><td>Label with Image</td><td>Spinbox</td></tr>
<tr><td>Listbox</td><td>Text</td></tr></table>
h1. ttk Widgets
* "Overrides" drawing of tkinter widgets
** Drawing now handled by theme engine
* Introduces new, modern widgets
* Change the "style"
** _ttk.Style().theme_names()_
** _ttk.Style().theme_use(style)_
h1. ttk Notebook
* Provides modern paged notebook of frames, accesible via tabs
* Sensible functionality
h1. ttk Treeview
* Implements tree, list, columned list, etc.
h1. ttk et cetera
!{border:0px; float:right; height:10em}ttk_widgets.png!
* Combobox
* CheckButton
* RadioButton
* Progressbar
* Separator
* Sizegrip
h1. Canvas
* Allows for simple primitive drawing within a Tk widget
* Opens up the door for custom widget behavior
h1. Events
* Tkinter events are relatively simple
** For buttons: _Button(text='Button Name', command=button_callback)_
* For more complex components, _bind_ method can be used
h1. Standard Dialogs
* File dialog
** _tkinter.filedialog_ or _tkFileDialog_
* Color chooser
** _tkinter.colorchooser_ or _tkColorChooser_
* Message box
** _tkinter.messagebox_ or _tkMessageBox_
h1. 2.7 and 3.x
* Python 2.7 and 3.x both contain Themed Tk
** Cross-version applications
* Python 2.x has different Tkinter namespace
** Python 3.x made tkinter slightly more Pythonic
** Need some ImportError exception magic for cross-version code
h1. Documentation
* Python library documentation on tkinter is arguably sparse
** ttk, however, is well-documented
* http://www.tkdocs.com/
** Reference for Tk in Tcl, Ruby, OCaml, and *Python*
h1. Summary
* Tkinter can be pretty sweet!
** Ships with (almost) all Python ports
** Now with modern widgets
* "Ugly" is gone with ttk
* Easy to build a quick GUI
h1. More Info
* Code
** ArmstrongJ on GitHub
** http://tx0.org/42y
* Presentation
** http://tx0.org/430
* Myself
** jeff@rainbow-100.com
** @fortranjeff on Twitter
|