Home Page Icon
Home Page
Table of Contents for
Table of Contents
Close
Table of Contents
by Bhaskar Chaudhary
Tkinter GUI Application Development HOTSHOT
Tkinter GUI Application Development HOTSHOT
Table of Contents
Tkinter GUI Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Meet Tkinter
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
The root window – your drawing board
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
The big picture
Widgets – building blocks for your GUI program
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
Getting to know core Tkinter widgets
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
Geometry management
Prepare for Lift Off
Engage Thrusters
The pack geometry manager
The grid geometry manager
The place geometry manager
Objective Complete – Mini Debriefing
Events and callbacks – adding life to programs
Engage Thrusters
Command binding
Passing arguments to the callback
Event binding
Event pattern
Levels of binding
Handling widget-specific variables
Objective Complete – Mini Debriefing
Classified Intel
Doing it in style
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
2. Making a Text Editor like Notepad
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Setting up the widgets
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Leveraging the power of built-in Text widget options
Engage Thrusters
Objective Complete – Mini Briefing
Indexing and tagging
Prepare for Lift Off
Index
Tags
Engage Thrusters
Objective Complete – Mini Briefing
Classified Intel
Working with forms and dialogs
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Briefing
Working with message boxes
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Briefing
The icon toolbar and View menu functions
Engage Thrusters
Objective Complete – Mini Briefing
Event handling and the context menu
Engage Thrusters
Objective Complete – Mini Briefing
Mission Accomplished
A Hotshot Challenge
3. Programmable Drum Machine
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
Setting up the GUI in OOP
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Completing the pattern editor
Engage Thrusters
Objective Complete – Mini Debriefing
Loading drum samples
Engage Thrusters
Objective Complete – Mini Debriefing
Playing the drum machine
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
Tkinter and threading
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
More beat patterns
Engage Thrusters
Objective Complete – Mini Debriefing
Object persistence
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
ttk-themed widgets
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
4. Game of Chess
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
Structuring our program
Prepare for Lift Off
Engage Thrusters
Step 1 – creating the GUI class
Step 2 – creating the chessboard
Step 3 – creating Tkinter mainloop
Objective Complete – Mini Debriefing
Classified Intel
Structuring chessboard-and-pieces-related data
Prepare for Lift Off
Engage Thrusters
Step 1 – creating a Piece superclass
Step 2 – creating individual child classes for all pieces
Step 3 – defining a method to return the piece instance
Step 4 – creating the Board class
Step 5 – displaying pieces on board for a given FEN notation
Step 6 – checking if a given coordinate is on the board
Step 7 – generating alphabetic and numeric notation
Step 8 – checking places occupied on the board
Step 9 – handling errors and exceptions
Objective Complete – Mini Debriefing
Adding pieces on the board
Prepare for Lift Off
Engage Thrusters
Step 1 – importing PIL
Step 2 – defining method to draw pieces on chessboard
Objective Complete – Mini Debriefing
Enforcing rules for pieces' movement
Prepare for Lift Off
Engage Thrusters
Step 1 – tracking moves available for all pieces from Pieces superclass
Step 2 – rules for the king, queen, rook and bishop class
Step 3 – rules for knight
Step 4 – rules for pawn
Objective Complete – Mini Debriefing
The chessboard logic
Engage Thrusters
Step 1: Tracking all Available Moves
Step 2: Getting Current Position of King
Step 3: Verifying if King is under Check
Objective Complete – Mini Debriefing
Making the chess functional
Engage Thrusters
Step 1 – updating the board for change in FEN notation
Step 2 – binding mouse click event
Step 3 – adding attribute to track selected piece and remaining pieces
Step 4 – identifying square clicked
Step 5 – getting the source and destination position
Step 6 – collecting list of moves to highlight
Step 7 – modifying draw_board to highlight allowed moves
Step 8 – defining attributes to keep game statistics
Step 9 – preshift validations
Step 10 – actual movement of pieces
Step 11 – Post movement updates
Step 12 – classes to handle exceptions and errors
Objective Complete – Mini Debriefing
Adding menu and an info frame
Engage Thrusters
Step 1 – creating top menu
Step 2 – adding the bottom frame to display game statistics
Step 3 – starting a new game from File | New game menu
Step 4 – updating bottom label after every move
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
5. Audio Player
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
Pyglet for audio manipulation
PMW Tkinter extension
Additional font
Getting the audio to play
Prepare for Lift Off
Engage Thrusters
Step 1 – creating the GUI class
Step 2 – creating the Play button and Add File button
Step 3 – toggling between play and pause
Step 4 – add file dialog
Step 5 – creating the Player class
Step 6 – running the application
Objective Complete – Mini Debriefing
Adding a playlist
Prepare for Lift Off
Engage Thrusters
Step 1 – adding an empty Listbox widget
Step 2 – identify track to play
Step 3 – adding items to the list
Step 4 – deleting items from the list
Step 5 – adding multiple items to the list
Step 6 – deleting all items
Objective Complete – Mini Debriefing
Adding more controls to the player
Engage Thrusters
Step 1 – fast forwarding a track
Step 2 – rewinding a track
Step 3 – pausing a track
Step 4 – setting the volume of playback
Step 5 – muting and unmuting a track
Step 6 – adding the control buttons
Step 7 – changing volume with the ttk Scale widget
Objective Complete – Mini Debriefing
Classified Intel
Adding the top display console
Prepare for Lift Off
Engage Thrusters
Step 1 – creating the top console and progress bar
Step 2 – getting the total duration of a track
Step 3 – updating console at launch of play
Step 4 – updating timer clock and progress bar at regular intervals
Objective Complete – Mini Debriefing
Looping over tracks
Engage Thrusters
Step 1 – creating the radio buttons
Step 2 – on end of song callback
Step 3 – what next?
Step 4 – fetching the next track
Objective Complete – Mini Debriefing
Adding the contextual menu
Engage Thrusters
Step 1 – creating the contextual menu
Step 2: overriding the close button
Objective Complete – Mini Debriefing
Adding a tooltip and finalizing our player
Prepare for Lift Off
PMW list of extensions
Widgets
Dialogs
Miscellaneous
Engage Thrusters
Step 1 – importing PMW
Step 2 – instantiating the Balloon widget
Step 3 – adding Balloon tooltips to all buttons in our player
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
6. Drawing an Application
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
Developing a bare bone GUI framework
Prepare for Lift Off
Engage Thrusters
Step 1 – creating the GUI framework class
Step 2 – creating menu builder
Step 3 – testing our new framework
Objective Complete – Mini Debriefing
Classified Intel
Structuring our drawing program
Engage Thrusters
Step 1 – importing framework
Step 2: building the top menu
Step 3 – undo operation on the Canvas widget
Step 4 – saving canvas objects
Step 5 – creating buttons in the left tool bar
Step 6 – adding command callback to buttons
Step 7 – creating color palettes and color selection dialog
Step 8 – setting color of background and foreground palette
Step 9 – displaying x and y coordinates of mouse movement
Objective Complete – Mini Debriefing
Handling mouse events
Engage Thrusters
Step 1 – binding mouse down, mouse motion, and mouse release over the canvas
Step 2 – calculating coordinates of mouse movement
Step 3 – updating the current mouse position label in the left tool bar
Objective Complete – Mini Debriefing
Drawing items on the canvas
Engage Thrusters
Step 1 – creating a tuple of methods
Step 2 – add icons to our toolbar buttons
Step 3 – keeping a tab on currently selected button
Step 4 – code for drawing line, rectangle, and oval shapes
Step 5 – code for drawing in continuous stroke
Step 6 – executing code dynamically
Step 7 – doing the actual drawing
Objective Complete – Mini Debriefing
Setting the options toolbar at the top
Engage Thrusters
Step 1 – showing the selected button icon at the top
Step 2 – adding the Combobox widget to let user select different fill options
Step 3 – modifying draw methods to add configurable options
Objective Complete – Mini Debriefing
Adding some more features
Engage Thrusters
Step 1 – extending our methods tuple
Step 2 – targeting a given item on the canvas
Step 3 – deleting items from the canvas
Step 4 – paint bucket feature
Step 5 – moving items on top of each other
Step 6 – dragging items on the canvas
Objective Complete – Mini Debriefing
Classified Intel
Working with item tags
Adding a tag
Retrieving tags
Getting items with a given tag
Built-in tags
Mission Accomplished
A Hotshot Challenge
7. Some Fun Project Ideas
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Building a screen saver
Engage Thrusters
Objective Complete – Mini Debriefing
Building a Snake game
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Creating a Weather Reporter
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
Creating a phonebook application
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Graphing with Tkinter
Engage Thrusters
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
A. Miscellaneous Tips
Mission Briefing
Tracing Tkinter variables
Widget traversal
Validating user input
Key Validation
Focus Out Validation
Formatting widget data
More on fonts
Finer Control over Font
Font Selector
Creating the GUI
Updating Sample Text
Working with Unicode characters
Declaring line encoding
Declaring file encoding
Tkinter class's hierarchy
Custom-made mixins
Tips for code cleanup and program optimization
Choose the right data structure
Working with Variables
Using Exceptions
Filter and map
Profiling
Other Optimization Tips
Distributing the Tkinter application
py2exe
py2app
PyInstaller
Other Freezing Tools
Limitations of Tkinter
Limited number of core widgets
No Support for printing
No support for newer image formats
Inactive development community
Alternatives to Tkinter
wxPython
PyQt
PySide
PyGTK
Other Options
Getting interactive help
Tkinter in Python 3.x
Conclusion
B. Quick Reference Sheets
Options common to widgets
Widget-specific options
The pack manager
The grid manager
The place manager
The event types
The event modifiers
The event details
Other event-related methods
List of available cursor
Potability issues
The basic widget methods
ttk widgets
The Toplevel window methods
Index
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
Cover
Next
Next Chapter
Tkinter GUI Application Development HOTSHOT
Table of Contents
Tkinter GUI Application Development HOTSHOT
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Meet Tkinter
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
The root window – your drawing board
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
The big picture
Widgets – building blocks for your GUI program
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
Getting to know core Tkinter widgets
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
Geometry management
Prepare for Lift Off
Engage Thrusters
The pack geometry manager
The grid geometry manager
The place geometry manager
Objective Complete – Mini Debriefing
Events and callbacks – adding life to programs
Engage Thrusters
Command binding
Passing arguments to the callback
Event binding
Event pattern
Levels of binding
Handling widget-specific variables
Objective Complete – Mini Debriefing
Classified Intel
Doing it in style
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
2. Making a Text Editor like Notepad
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Setting up the widgets
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Leveraging the power of built-in Text widget options
Engage Thrusters
Objective Complete – Mini Briefing
Indexing and tagging
Prepare for Lift Off
Index
Tags
Engage Thrusters
Objective Complete – Mini Briefing
Classified Intel
Working with forms and dialogs
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Briefing
Working with message boxes
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Briefing
The icon toolbar and View menu functions
Engage Thrusters
Objective Complete – Mini Briefing
Event handling and the context menu
Engage Thrusters
Objective Complete – Mini Briefing
Mission Accomplished
A Hotshot Challenge
3. Programmable Drum Machine
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
Setting up the GUI in OOP
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Completing the pattern editor
Engage Thrusters
Objective Complete – Mini Debriefing
Loading drum samples
Engage Thrusters
Objective Complete – Mini Debriefing
Playing the drum machine
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
Tkinter and threading
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
More beat patterns
Engage Thrusters
Objective Complete – Mini Debriefing
Object persistence
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
ttk-themed widgets
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
4. Game of Chess
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
Structuring our program
Prepare for Lift Off
Engage Thrusters
Step 1 – creating the GUI class
Step 2 – creating the chessboard
Step 3 – creating Tkinter mainloop
Objective Complete – Mini Debriefing
Classified Intel
Structuring chessboard-and-pieces-related data
Prepare for Lift Off
Engage Thrusters
Step 1 – creating a Piece superclass
Step 2 – creating individual child classes for all pieces
Step 3 – defining a method to return the piece instance
Step 4 – creating the Board class
Step 5 – displaying pieces on board for a given FEN notation
Step 6 – checking if a given coordinate is on the board
Step 7 – generating alphabetic and numeric notation
Step 8 – checking places occupied on the board
Step 9 – handling errors and exceptions
Objective Complete – Mini Debriefing
Adding pieces on the board
Prepare for Lift Off
Engage Thrusters
Step 1 – importing PIL
Step 2 – defining method to draw pieces on chessboard
Objective Complete – Mini Debriefing
Enforcing rules for pieces' movement
Prepare for Lift Off
Engage Thrusters
Step 1 – tracking moves available for all pieces from Pieces superclass
Step 2 – rules for the king, queen, rook and bishop class
Step 3 – rules for knight
Step 4 – rules for pawn
Objective Complete – Mini Debriefing
The chessboard logic
Engage Thrusters
Step 1: Tracking all Available Moves
Step 2: Getting Current Position of King
Step 3: Verifying if King is under Check
Objective Complete – Mini Debriefing
Making the chess functional
Engage Thrusters
Step 1 – updating the board for change in FEN notation
Step 2 – binding mouse click event
Step 3 – adding attribute to track selected piece and remaining pieces
Step 4 – identifying square clicked
Step 5 – getting the source and destination position
Step 6 – collecting list of moves to highlight
Step 7 – modifying draw_board to highlight allowed moves
Step 8 – defining attributes to keep game statistics
Step 9 – preshift validations
Step 10 – actual movement of pieces
Step 11 – Post movement updates
Step 12 – classes to handle exceptions and errors
Objective Complete – Mini Debriefing
Adding menu and an info frame
Engage Thrusters
Step 1 – creating top menu
Step 2 – adding the bottom frame to display game statistics
Step 3 – starting a new game from File | New game menu
Step 4 – updating bottom label after every move
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
5. Audio Player
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
Pyglet for audio manipulation
PMW Tkinter extension
Additional font
Getting the audio to play
Prepare for Lift Off
Engage Thrusters
Step 1 – creating the GUI class
Step 2 – creating the Play button and Add File button
Step 3 – toggling between play and pause
Step 4 – add file dialog
Step 5 – creating the Player class
Step 6 – running the application
Objective Complete – Mini Debriefing
Adding a playlist
Prepare for Lift Off
Engage Thrusters
Step 1 – adding an empty Listbox widget
Step 2 – identify track to play
Step 3 – adding items to the list
Step 4 – deleting items from the list
Step 5 – adding multiple items to the list
Step 6 – deleting all items
Objective Complete – Mini Debriefing
Adding more controls to the player
Engage Thrusters
Step 1 – fast forwarding a track
Step 2 – rewinding a track
Step 3 – pausing a track
Step 4 – setting the volume of playback
Step 5 – muting and unmuting a track
Step 6 – adding the control buttons
Step 7 – changing volume with the ttk Scale widget
Objective Complete – Mini Debriefing
Classified Intel
Adding the top display console
Prepare for Lift Off
Engage Thrusters
Step 1 – creating the top console and progress bar
Step 2 – getting the total duration of a track
Step 3 – updating console at launch of play
Step 4 – updating timer clock and progress bar at regular intervals
Objective Complete – Mini Debriefing
Looping over tracks
Engage Thrusters
Step 1 – creating the radio buttons
Step 2 – on end of song callback
Step 3 – what next?
Step 4 – fetching the next track
Objective Complete – Mini Debriefing
Adding the contextual menu
Engage Thrusters
Step 1 – creating the contextual menu
Step 2: overriding the close button
Objective Complete – Mini Debriefing
Adding a tooltip and finalizing our player
Prepare for Lift Off
PMW list of extensions
Widgets
Dialogs
Miscellaneous
Engage Thrusters
Step 1 – importing PMW
Step 2 – instantiating the Balloon widget
Step 3 – adding Balloon tooltips to all buttons in our player
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
6. Drawing an Application
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Mission Checklist
Developing a bare bone GUI framework
Prepare for Lift Off
Engage Thrusters
Step 1 – creating the GUI framework class
Step 2 – creating menu builder
Step 3 – testing our new framework
Objective Complete – Mini Debriefing
Classified Intel
Structuring our drawing program
Engage Thrusters
Step 1 – importing framework
Step 2: building the top menu
Step 3 – undo operation on the Canvas widget
Step 4 – saving canvas objects
Step 5 – creating buttons in the left tool bar
Step 6 – adding command callback to buttons
Step 7 – creating color palettes and color selection dialog
Step 8 – setting color of background and foreground palette
Step 9 – displaying x and y coordinates of mouse movement
Objective Complete – Mini Debriefing
Handling mouse events
Engage Thrusters
Step 1 – binding mouse down, mouse motion, and mouse release over the canvas
Step 2 – calculating coordinates of mouse movement
Step 3 – updating the current mouse position label in the left tool bar
Objective Complete – Mini Debriefing
Drawing items on the canvas
Engage Thrusters
Step 1 – creating a tuple of methods
Step 2 – add icons to our toolbar buttons
Step 3 – keeping a tab on currently selected button
Step 4 – code for drawing line, rectangle, and oval shapes
Step 5 – code for drawing in continuous stroke
Step 6 – executing code dynamically
Step 7 – doing the actual drawing
Objective Complete – Mini Debriefing
Setting the options toolbar at the top
Engage Thrusters
Step 1 – showing the selected button icon at the top
Step 2 – adding the Combobox widget to let user select different fill options
Step 3 – modifying draw methods to add configurable options
Objective Complete – Mini Debriefing
Adding some more features
Engage Thrusters
Step 1 – extending our methods tuple
Step 2 – targeting a given item on the canvas
Step 3 – deleting items from the canvas
Step 4 – paint bucket feature
Step 5 – moving items on top of each other
Step 6 – dragging items on the canvas
Objective Complete – Mini Debriefing
Classified Intel
Working with item tags
Adding a tag
Retrieving tags
Getting items with a given tag
Built-in tags
Mission Accomplished
A Hotshot Challenge
7. Some Fun Project Ideas
Mission Briefing
Why Is It Awesome?
Your Hotshot Objectives
Building a screen saver
Engage Thrusters
Objective Complete – Mini Debriefing
Building a Snake game
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Creating a Weather Reporter
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Classified Intel
Creating a phonebook application
Prepare for Lift Off
Engage Thrusters
Objective Complete – Mini Debriefing
Graphing with Tkinter
Engage Thrusters
Objective Complete – Mini Debriefing
Mission Accomplished
A Hotshot Challenge
A. Miscellaneous Tips
Mission Briefing
Tracing Tkinter variables
Widget traversal
Validating user input
Key Validation
Focus Out Validation
Formatting widget data
More on fonts
Finer Control over Font
Font Selector
Creating the GUI
Updating Sample Text
Working with Unicode characters
Declaring line encoding
Declaring file encoding
Tkinter class's hierarchy
Custom-made mixins
Tips for code cleanup and program optimization
Choose the right data structure
Working with Variables
Using Exceptions
Filter and map
Profiling
Other Optimization Tips
Distributing the Tkinter application
py2exe
py2app
PyInstaller
Other Freezing Tools
Limitations of Tkinter
Limited number of core widgets
No Support for printing
No support for newer image formats
Inactive development community
Alternatives to Tkinter
wxPython
PyQt
PySide
PyGTK
Other Options
Getting interactive help
Tkinter in Python 3.x
Conclusion
B. Quick Reference Sheets
Options common to widgets
Widget-specific options
The pack manager
The grid manager
The place manager
The event types
The event modifiers
The event details
Other event-related methods
List of available cursor
Potability issues
The basic widget methods
ttk widgets
The Toplevel window methods
Index
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset