Introduction to Tkinter(1).pdf
(
732 KB
)
Pobierz
An Introduction to Tkinter
Review Copy. Do not redistribute! 1999-12-01 22:15
An Introduction to Tkinter
by Fredrik Lundh
Copyright © 1999 by Fredrik Lundh
Fredrik Lundh
Copyright (c) 1999 by Fredrik Lundh
Review Copy. Do not redistribute! 1999-12-01 22:15
Table of Contents
Toolbars ......................................................................................................................... 26
Status Bars.....................................................................................................................27
9. Dialog Windows ................................................................................................................. 29
Grid Layouts .................................................................................................................. 34
Validating Data.............................................................................................................. 36
II. Tkinter Reference............................................................................................ 37
10. The BitmapImage Class ................................................................................................... 38
When to use the BitmapImage Class ........................................................................... 38
Patterns.......................................................................................................................... 38
Methods .........................................................................................................................38
Options .......................................................................................................................... 38
11. The Button Widget ............................................................................................................40
When to use the Button Widget ................................................................................... 40
Patterns.......................................................................................................................... 40
Methods .........................................................................................................................41
Helpers........................................................................................................................... 41
Options .......................................................................................................................... 41
12. The Canvas Widget ...........................................................................................................44
When to use the Canvas Widget ................................................................................... 44
Concepts ........................................................................................................................44
Items ..................................................................................................................... 44
Coordinate Systems ............................................................................................. 45
Item Specifiers ..................................................................................................... 45
Printing ................................................................................................................. 46
Patterns.......................................................................................................................... 46
Methods .........................................................................................................................46
Printing ................................................................................................................. 48
Searching for Items .............................................................................................. 49
Manipulating Tags ............................................................................................... 50
Special Methods for Text Items............................................................................51
Scrolling.................................................................................................................51
Options .......................................................................................................................... 52
13. The Canvas Arc Item ........................................................................................................ 54
Methods .........................................................................................................................54
Options .......................................................................................................................... 55
14. The Canvas Bitmap Item.................................................................................................. 57
Bitmaps .......................................................................................................................... 57
Methods .........................................................................................................................58
Options .......................................................................................................................... 58
15. The Canvas Image Item.................................................................................................... 59
Methods .........................................................................................................................59
coords ................................................................................................................... 59
itemconfigure ....................................................................................................... 59
Options .......................................................................................................................... 59
16. The Canvas Line Item....................................................................................................... 61
Methods .........................................................................................................................61
Options .......................................................................................................................... 61
Preface ....................................................................................................................i
I. Introducing Tkinter ............................................................................................2
1. What's Tkinter?......................................................................................................................1
2. Hello, Tkinter ....................................................................................................................... 2
Running the Example ..................................................................................................... 2
Details .............................................................................................................................. 2
3. Hello, Again .......................................................................................................................... 4
Running the Example ..................................................................................................... 4
Details .............................................................................................................................. 5
More on widget references ............................................................................................. 6
More on widget names.................................................................................................... 6
4. Tkinter Classes ..................................................................................................................... 8
Widget classes .................................................................................................................8
Mixins .............................................................................................................................. 9
Implementation mixins ......................................................................................... 9
Geometry mixins .................................................................................................... 9
Widget configuration management ...................................................................... 9
5. Widget Configuration.......................................................................................................... 11
Configuration Interface ................................................................................................. 11
Backwards Compatibility...............................................................................................12
6. Widget Styling .....................................................................................................................13
Colors ..............................................................................................................................13
Color Names ..........................................................................................................13
RGB Specifications................................................................................................13
Fonts .............................................................................................................................. 14
Font descriptors ................................................................................................... 14
Font names ............................................................................................................15
System fonts ......................................................................................................... 16
X Font Descriptors ............................................................................................... 16
Text Formatting .............................................................................................................17
Borders ...........................................................................................................................17
Relief ......................................................................................................................17
Focus Highlights .................................................................................................. 18
Cursors........................................................................................................................... 18
7. Events and Bindings........................................................................................................... 19
Events ............................................................................................................................ 19
The Event Object ...................................................................................................21
Instance and Class Bindings.................................................................................21
Protocols ............................................................................................................... 23
Other Protocols .................................................................................................... 24
8. Application Windows......................................................................................................... 25
Base Windows ............................................................................................................... 25
Menus ............................................................................................................................ 25
i
ii
Copyright (c) 1999 by Fredrik Lundh
Review Copy. Do not redistribute! 1999-12-01 22:15
17. The Canvas Oval Item.......................................................................................................63
Methods .........................................................................................................................63
Options .......................................................................................................................... 63
18. The Canvas Polygon Item ................................................................................................ 64
Methods .........................................................................................................................64
Options .......................................................................................................................... 64
19. The Canvas Rectangle Item.............................................................................................. 66
Methods .........................................................................................................................66
Options .......................................................................................................................... 66
20. The Canvas Text Item ...................................................................................................... 67
Methods .........................................................................................................................67
Options .......................................................................................................................... 67
21. The Canvas Window Item ................................................................................................ 69
Methods .........................................................................................................................69
Options .......................................................................................................................... 69
22. The Checkbutton Widget ................................................................................................. 70
When to use the Checkbutton Widget ......................................................................... 70
Patterns.......................................................................................................................... 70
Methods ..........................................................................................................................71
Options ...........................................................................................................................71
23. The DoubleVar Class........................................................................................................ 75
When to use the DoubleVar Class ................................................................................ 75
Patterns.......................................................................................................................... 75
Methods .........................................................................................................................75
24. The Entry Widget ............................................................................................................. 76
When to use the Entry Widget ..................................................................................... 76
Concepts ........................................................................................................................76
Indexes.................................................................................................................. 76
Patterns.......................................................................................................................... 76
Methods .........................................................................................................................77
Selection Methods................................................................................................ 77
Scrolling Methods ................................................................................................ 78
Options .......................................................................................................................... 78
25. The Font Class ..................................................................................................................80
Patterns..........................................................................................................................80
Methods .........................................................................................................................80
Functions .......................................................................................................................80
Options .......................................................................................................................... 81
26. The Frame Widget ...........................................................................................................82
When to use the Frame Widget .................................................................................... 82
Patterns.......................................................................................................................... 82
Methods .........................................................................................................................82
Options .......................................................................................................................... 82
27. The Grid Geometry Manager........................................................................................... 84
When to use the Grid Manager .................................................................................... 84
Patterns.......................................................................................................................... 84
Methods .........................................................................................................................86
Widget Methods ................................................................................................... 86
Manager Methods ................................................................................................ 87
Options .......................................................................................................................... 87
28. The IntVar Class............................................................................................................... 89
When to use the IntVar Class ....................................................................................... 89
Patterns.......................................................................................................................... 89
Methods .........................................................................................................................89
29. The Label Widget ............................................................................................................. 90
When to use the Label Widget......................................................................................90
Patterns.......................................................................................................................... 90
Methods .........................................................................................................................91
Options .......................................................................................................................... 91
30. The Listbox Widget ..........................................................................................................93
When to use the Listbox Widget .................................................................................. 93
Patterns.......................................................................................................................... 93
Methods .........................................................................................................................96
Selection Methods................................................................................................ 97
Scrolling Methods ................................................................................................ 97
Options .......................................................................................................................... 98
31. The Menu Widget ........................................................................................................... 100
When to use the Menu Widget ................................................................................... 100
Patterns........................................................................................................................100
Methods ....................................................................................................................... 102
Displaying Menus .............................................................................................. 104
Options ........................................................................................................................ 104
32. The Menubutton Widget ............................................................................................... 107
When to use the Menubutton Widget ........................................................................ 107
Patterns........................................................................................................................107
Methods ....................................................................................................................... 107
Options ........................................................................................................................ 107
33. The Message Widget ...................................................................................................... 108
When to use the Message Widget............................................................................... 108
Patterns........................................................................................................................108
Methods ....................................................................................................................... 108
Options ........................................................................................................................ 108
34. The Pack Geometry Manager .........................................................................................110
When to use the Pack Manager ...................................................................................110
Patterns.........................................................................................................................110
Methods ........................................................................................................................110
Widget Methods ..................................................................................................110
Manager Methods ...............................................................................................110
Options .........................................................................................................................111
35. The PhotoImage Class..................................................................................................... 112
When to use the PhotoImage Class ............................................................................. 112
Patterns......................................................................................................................... 112
Methods ........................................................................................................................112
Options .........................................................................................................................113
36. The Place Geometry Manager ........................................................................................ 115
When to use the Place Manager .................................................................................. 115
iii
iv
Copyright (c) 1999 by Fredrik Lundh
Review Copy. Do not redistribute! 1999-12-01 22:15
Patterns......................................................................................................................... 115
Methods ........................................................................................................................116
Options .........................................................................................................................117
37. The Radiobutton Widget.................................................................................................118
When to use the Radiobutton Widget.........................................................................118
Patterns.........................................................................................................................118
Methods ........................................................................................................................119
Options ........................................................................................................................ 120
38. The Scale Widget............................................................................................................123
When to use the Scale Widget .................................................................................... 123
Patterns........................................................................................................................123
Methods ....................................................................................................................... 123
Options ........................................................................................................................ 123
39. The Scrollbar Widget ......................................................................................................125
When to use the Scrollbar Widget...............................................................................125
Patterns.........................................................................................................................125
Methods ....................................................................................................................... 126
Options ........................................................................................................................ 126
40. The StringVar Class ....................................................................................................... 129
When to use the StringVar Class ................................................................................ 129
Patterns........................................................................................................................129
Methods ....................................................................................................................... 129
41. The Text Widget .............................................................................................................130
When to use the Text Widget ..................................................................................... 130
Concepts ...................................................................................................................... 130
Indexes................................................................................................................ 130
Lines and columns ..................................................................................... 131
Line endings ............................................................................................... 131
Named indexes ........................................................................................... 131
Coordinates ............................................................................................... 132
Embedded objects ..................................................................................... 132
Expressions ............................................................................................... 132
Marks .................................................................................................................. 132
Tags ..................................................................................................................... 133
Patterns.........................................................................................................................135
Methods ........................................................................................................................137
Methods for Marks............................................................................................. 138
Methods for Embedded Windows..................................................................... 139
Methods for Embedded Images ........................................................................ 140
image_create ............................................................................................. 140
index ...........................................................................................................141
delete ..........................................................................................................141
image_cget ................................................................................................. 141
image_config.............................................................................................. 141
image_names ............................................................................................. 141
Methods for Tags ................................................................................................141
tag_add...................................................................................................... 142
tag_remove................................................................................................ 142
tag_delete .................................................................................................. 142
tag_config.................................................................................................. 142
tag_cget ..................................................................................................... 142
tag_bind .................................................................................................... 142
tag_unbind ................................................................................................ 142
tag_names ................................................................................................. 142
tag_nextrange ........................................................................................... 143
tag_prevrange ........................................................................................... 143
tag_lower................................................................................................... 143
tag_raise .................................................................................................... 143
tag_ranges ................................................................................................. 143
Methods for Selections ...................................................................................... 143
Methods for Rendering...................................................................................... 144
bbox ........................................................................................................... 144
dlineinfo..................................................................................................... 144
Methods for Printing.......................................................................................... 144
Methods for Searching....................................................................................... 144
search......................................................................................................... 144
Methods for Scrolling ........................................................................................ 145
scan_mark, scan_dragto .......................................................................... 145
xview, yview............................................................................................... 145
xview, yview............................................................................................... 145
xview, yview............................................................................................... 145
yview_pickplace ........................................................................................ 146
Options ........................................................................................................................ 146
42. The Toplevel Widget ...................................................................................................... 149
When to use the Toplevel Widget............................................................................... 149
Methods ....................................................................................................................... 149
Options ........................................................................................................................ 149
43. Basic Widget Methods .................................................................................................... 151
Configuration ............................................................................................................... 151
config ................................................................................................................... 151
config ................................................................................................................... 151
cget ....................................................................................................................... 151
keys ...................................................................................................................... 151
Event processing ..........................................................................................................152
mainloop ..............................................................................................................152
quit .......................................................................................................................152
update ..................................................................................................................152
update_idletasks .................................................................................................152
focus_set..............................................................................................................152
focus_displayof ...................................................................................................152
focus_force ..........................................................................................................152
focus_get .............................................................................................................152
focus_lastfor........................................................................................................152
tk_focusNext .......................................................................................................153
tk_focusPrev........................................................................................................153
grab_current .......................................................................................................153
v
vi
Copyright (c) 1999 by Fredrik Lundh
Review Copy. Do not redistribute! 1999-12-01 22:15
grab_release ........................................................................................................153
grab_set ...............................................................................................................153
grab_set_global ..................................................................................................153
grab_status..........................................................................................................153
wait_variable.......................................................................................................153
wait_visibility......................................................................................................153
wait_window ...................................................................................................... 154
Event callbacks ............................................................................................................ 154
bind ..................................................................................................................... 154
unbind................................................................................................................. 154
bind_all .............................................................................................................. 154
unbind_all .......................................................................................................... 154
bind_class........................................................................................................... 154
unbind_class ...................................................................................................... 154
bindtags ...............................................................................................................155
bindtags ...............................................................................................................155
Alarm handlers and other non-event callbacks..........................................................155
after......................................................................................................................155
after_cancel .........................................................................................................155
after......................................................................................................................155
after_idle .............................................................................................................155
Window management ................................................................................................. 156
lift ........................................................................................................................ 156
lower ................................................................................................................... 156
Window Related Information..................................................................................... 156
winfo_cells ......................................................................................................... 156
winfo_children ................................................................................................... 156
winfo_class ......................................................................................................... 156
winfo_colormapfull ........................................................................................... 156
winfo_containing ............................................................................................... 156
winfo_depth ........................................................................................................157
winfo_exists ........................................................................................................157
winfo_pixels ........................................................................................................157
winfo_geometry ..................................................................................................157
winfo_width, winfo_height ................................................................................157
winfo_id...............................................................................................................157
winfo_ismapped .................................................................................................157
winfo_manager ...................................................................................................157
winfo_name ....................................................................................................... 158
winfo_parent ...................................................................................................... 158
winfo_pathname ................................................................................................ 158
winfo_reqheight, winfo_reqwidth .................................................................... 158
winfo_rootx, winfo_rooty ................................................................................. 158
winfo_screen ...................................................................................................... 158
winfo_screencells............................................................................................... 158
winfo_screendepth ............................................................................................ 158
winfo_screenwidth, winfo_screenheight ......................................................... 159
winfo_screenmmwidth, winfo_screenmmheight ............................................ 159
winfo_screenvisual ............................................................................................ 159
winfo_toplevel.................................................................................................... 159
winfo_visual ....................................................................................................... 159
winfo_x, winfo_y ............................................................................................... 159
Miscellaneous .............................................................................................................. 159
bell....................................................................................................................... 159
clipboard_append .............................................................................................. 159
clipboard_clear .................................................................................................. 159
selection_clear ................................................................................................... 160
selection_get ...................................................................................................... 160
selection_handle ................................................................................................ 160
selection_own .................................................................................................... 160
selection_own_get ............................................................................................. 160
tk_focusFollowsMouse ...................................................................................... 160
tk_strictMotif ..................................................................................................... 160
winfo_rgb ........................................................................................................... 160
Tkinter Interface Methods.......................................................................................... 160
getboolean .......................................................................................................... 160
getdouble ............................................................................................................ 160
getint .................................................................................................................... 161
register ................................................................................................................. 161
winfo_atom .........................................................................................................161
winfo_atomname ................................................................................................161
Option Database...........................................................................................................161
option_add ..........................................................................................................161
option_clear ........................................................................................................161
option_get ...........................................................................................................161
option_readfile.................................................................................................... 161
44. Toplevel Window Methods............................................................................................ 162
Visibility Methods ....................................................................................................... 162
deiconify ............................................................................................................. 162
iconify ................................................................................................................. 162
withdraw............................................................................................................. 162
state..................................................................................................................... 162
Style Methods .............................................................................................................. 162
title ...................................................................................................................... 162
group ................................................................................................................... 162
transient.............................................................................................................. 163
overrideredirect.................................................................................................. 163
Window Geometry Methods....................................................................................... 163
geometry ............................................................................................................. 163
geometry ............................................................................................................. 163
aspect .................................................................................................................. 163
maxsize ............................................................................................................... 163
minsize................................................................................................................ 163
resizable .............................................................................................................. 163
Icon Methods............................................................................................................... 164
iconbitmap.......................................................................................................... 164
vii
viii
Copyright (c) 1999 by Fredrik Lundh
Plik z chomika:
musli_com
Inne pliki z tego folderu:
3-Cours DEUG(1).pdf
(181 KB)
5-Cours DEUG(2).pdf
(170 KB)
6-Cours DEUG(1).pdf
(59 KB)
7-Cours DEUG(1).pdf
(185 KB)
Algorithmes et programmation en Pascal(2).pdf
(254 KB)
Inne foldery tego chomika:
CloudStack
distribution
dsp
electronics
LPI
Zgłoś jeśli
naruszono regulamin