Book Image

Tkinter GUI Programming by Example

Book Image

Tkinter GUI Programming by Example

Overview of this book

Tkinter is a modular, cross-platform application development toolkit for Python. When developing GUI-rich applications, the most important choices are which programming language(s) and which GUI framework to use. Python and Tkinter prove to be a great combination. This book will get you familiar with Tkinter by having you create fun and interactive projects. These projects have varying degrees of complexity. We'll start with a simple project, where you'll learn the fundamentals of GUI programming and the basics of working with a Tkinter application. After getting the basics right, we'll move on to creating a project of slightly increased complexity, such as a highly customizable Python editor. In the next project, we'll crank up the complexity level to create an instant messaging app. Toward the end, we'll discuss various ways of packaging our applications so that they can be shared and installed on other machines without the user having to learn how to install and run Python programs.
Table of Contents (18 chapters)
Title Page
Copyright and Credits
Packt Upsell
Contributors
Preface
Index

Searching text


When we need to find a specific piece of text within a Text widget, there is a method called search which will allow us to do this easily.

The search method can take quite a lot of arguments:

  • pattern: The pattern to match. This can be either an exact match or a regular expression.
  • index: Where to begin the search from.
  • stopindex: Where to stop ending a search. If this is not specified, the search will loop.
  • forwards: Whether to search from the top to the bottom (this is the default).
  • backwards: Whether to search from bottom to top.
  • exact: Exact match instead of a regular expression (this is the default).
  • regexp: Indicates that the pattern supplied is a regular expression.
  • nocase: Whether to ignore case.
  • count: A variable which will be updated with the length of the match.

The only mandatory arguments are the search pattern and the starting index.

The Search method will return the index of the beginning of the match and, if supplied, a variable for the count argument; the length of the...