- 340 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
Tkinter GUI Programming by Example
About This Book
Leverage the power of Python and its de facto GUI framework to build highly interactive interfacesAbout This Book⢠The fundamentals of Python and GUI programming with Tkinter.⢠Create multiple cross-platform projects by integrating a host of third-party libraries and tools.⢠Build beautiful and highly-interactive user interfaces that target multiple devices.Who This Book Is ForThis book is for beginners to GUI programming who haven't used Tkinter yet and are eager to start building great-looking and user-friendly GUIs. Prior knowledge of Python programming is expected.What You Will Learn⢠Create a scrollable frame via theCanvas widget⢠Use the pack geometry manager andFrame widget to control layout⢠Learn to choose a data structurefor a game⢠Group Tkinter widgets, such asbuttons, canvases, and labels⢠Create a highly customizablePython editor⢠Design and lay out a chat windowIn DetailTkinter 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.Style and approachStep by Step guide with real world examples
Frequently asked questions
Information
The Finishing Touches â Sound and Animation
- Making graphics move on a canvas
- Keeping control of the GUI while animations are playing
- Integrating the pygame library with Tkinter and playing sounds
- Expanding and re-structuring a larger application using Python's module system
Python's module system
# mymod.py
myvariable = 15
def do_a_thing():
print('mymod is doing something')
def do_another_thing():
print('mymod is doing something else, and myvariable is', myvariable)
>>> import mymod
>>> mymod.do_a
mymod.do_a_thing( mymod.do_another_thing(
>>> mymod.do_a_thing()
mymod is doing something
>>> mymod.do_another_thing()
mymod is doing something else, and myvariable is 15
>>> import sys
>>> import os
>>> sys.path
['', '/usr/lib/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/usr/lib64/python3.6/site-packages', '/usr/lib64/python3.6/_import_failed', '/usr/lib/python3.6/site-packages']
>>> os.environ['PYTHONPATH']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib64/python3.6/os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'PYTHONPATH'
myvariable = ['important', 'list']
>>> import mymod
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'mymod']
>>> dir(mymod)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'do_a_thing', 'do_another_thing', 'myvariable']
>>> mymod.myvariable
['important', 'list']
>>> mymod.do_another_thing()
mymod is doing something else, and myvariable is ['important', 'list']
>>> myvariable = ['silly', 'list']
>>> mymod.myvariable
['important', 'list']
>>> mymod.do_another_thing()
mymod is doing something else, and myvariable is ['important', 'list']
>>> from mymod import *
>>> dir()
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'do_a_thing', 'do_another_thing', 'myvariable']
>>> myvariable
['important', 'list']
>>> myvariable.append('junk')
>>> do_another_thing()
mymod is doing something else, and myvariable is ['important', 'list', 'junk']
>>> myvariable.remove('important')
>>> do_anot...
Table of contents
- Title Page
- Copyright and Credits
- Packt Upsell
- Contributors
- Preface
- Meet Tkinter
- Back to the Command Line â Basic Blackjack
- Jack is Back in Style â the Blackjack GUI
- The Finishing Touches â Sound and Animation
- Creating a Highly Customizable Python Editor
- Color Me Impressed! â Adding Syntax Highlighting
- Not Just for Restaurants â All About Menus
- Talk Python to Me â a Chat Application
- Connecting â Getting Our Chat Client Online
- Making Friends â Finishing Our Chat Application
- Wrapping Up â Packaging Our Applications to Share
- Other Books You May Enjoy