An Introduction To Tkinter - Washington State University

1y ago
5 Views
1 Downloads
732.61 KB
90 Pages
Last View : 18d ago
Last Download : 3m ago
Upload by : Aiyana Dorn
Transcription

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 Preface .i Toolbars . 26 Status Bars. 27 9. Dialog Windows . 29 Grid Layouts . 34 Validating Data. 36 I. Introducing Tkinter .2 II. Tkinter Reference. 37 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 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 i ii Table of Contents 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.

python hello1.py The following window appears. Figure 2-1. Running the program To stop the program, just close the window. Details We start by importing the Tkinter module. It contains all classes, functions and other things needed to work with the Tk toolkit. In most cases, you can simply import everything from Tkinter into your module's .

Related Documents:

In addition to the Tk interface module, Tkinter includes a number of Python modules. The two most important modules are the Tkinter module itself, and a module called Tkconstants. The former automatically imports the latter, so to use Tkinter, all you need to do is to import one module: import Tkinter Or,

Python 1 and 2; renamed to tkinter in Python 3). If Tkinter is available, then no errors occur, as demonstrated in the following: import tkinter If your Python interpreter was not compiled with Tkinter enabled, the module import fails. You might need to recompile your Python interpreter to gain access to Tkinter. This usually

Tkinter is largely unchanged between python 2 and python 3, with the major difference being that the tkinter package and modules were renamed. Importing in python 2.x In python 2.x, the tkinter package is named Tkinter, and related packages have their own names. For example, the following shows a typical set of import statements for python 2.x:

"Tkinter is Python's de facto standard GUI (Graphical User Interface) package. It is a thin object oriented layer on top of Tcl/Tk." Tkinter examples you may have seen. Tkinter examples you may have seen. With ttk, you get a nicer look. Themed widgets can match the platform. .

Setup Begin with this import statement: from tkinter import * Note: In earlier versions of Python, this module was called Tkinter, not tkinter Then create an object of type Tk: top Tk() This is the top-level window of your GUI program You can use any name for it; in these slide

programming in Python, using Tkinter . There are several GUI interfaces available in Python: Tkinter is the Python interface to the Tk GUI toolkit. wxPython is an open-source Python interface for wxWindows. JPython is a Python port for Java which gives Python scripts access

Based on Tcl/Tk. Popular open-source scripting language/GUI widget set developed by John Ousterhout (90s) Tk used in a wide variety of other languages (Perl, Ruby, PHP, etc.) Cross-platform (Unix/Windows/MacOS) It's small ( 25 basic widgets) 3 Tkinter Hello World A very short example: from Tkinter import Label

This is a digital copy of a book that was preserved for generations on library shelves before it was carefully scanned by Google as part of a project