Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Python GUI Programming Cookbook, Second Edition
Python GUI Programming Cookbook, Second Edition

Python GUI Programming Cookbook, Second Edition: Use recipes to develop responsive and powerful GUIs using Tkinter , Second Edition

Arrow left icon
Profile Icon Burkhard Meier
Arrow right icon
Mex$631.99 Mex$902.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.4 (5 Ratings)
eBook May 2017 444 pages 2nd Edition
eBook
Mex$631.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial
Arrow left icon
Profile Icon Burkhard Meier
Arrow right icon
Mex$631.99 Mex$902.99
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.4 (5 Ratings)
eBook May 2017 444 pages 2nd Edition
eBook
Mex$631.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial
eBook
Mex$631.99 Mex$902.99
Paperback
Mex$1128.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Table of content icon View table of contents Preview book icon Preview Book

Python GUI Programming Cookbook, Second Edition

Creating the GUI Form and Adding Widgets

In this chapter, we start creating amazing GUIs using Python 3.6 and above. We will cover the following topics:

  • Creating our first Python GUI
  • Preventing the GUI from being resized
  • Adding a label to the GUI form
  • Creating buttons and changing their text property
  • Text box widgets
  • Setting the focus to a widget and disabling widgets
  • Combo box widgets
  • Creating a check button with different initial states
  • Using radio button widgets
  • Using scrolled text widgets
  • Adding several widgets in a loop

Introduction

In this chapter, we will develop our first GUI in Python. We will start with the minimum code required to build a running GUI application. Each recipe then adds different widgets to the GUI form.

In the first two recipes, we will show the entire code, consisting of only a few lines of code. In the following recipes, we will only show the code to be added to the previous recipes.

By the end of this chapter, we will have created a working GUI application that consists of labels, buttons, text boxes, combo boxes, check buttons in various states, as well as radio buttons that change the background color of the GUI.

At the beginning of each chapter, I will show the Python modules that belong to each chapter. I will then reference the different modules that belong to the code shown, studied and run.

Here is the overview of Python modules (ending in a .py extension) for this chapter:

Creating our first Python GUI

Python is a very powerful programming language. It ships with the built-in tkinter module. In only a few lines of code (four, to be precise) we can build our first Python GUI.

Getting ready

To follow this recipe, a working Python development environment is a prerequisite. The IDLE GUI, which ships with Python, is enough to start. IDLE was built using tkinter!

  • All the recipes in this book were developed using Python 3.6 on a Windows 10 64-bit OS. They have not been tested on any other configuration. As Python is a cross-platform language, the code from each recipe is expected to run everywhere.
  • If you are using a Mac, it does come with built-in Python, yet it might be missing some modules such as tkinter, which we will use throughout this book.
  • We are using Python 3.6, and the creator of Python intentionally chose not to make it backwards compatible with Python 2. If you are using a Mac or Python 2, you might have to install Python 3.6 from www.python.org in order to successfully run the recipes in this book.
  • If you really wish to run the code in this book on Python 2.7, you will have to make some adjustments. For example, tkinter in Python 2.x has an uppercase T. The Python 2.7 print statement is a function in Python 3.6 and requires parentheses.
  • While the EOL (End Of Life) for the Python 2.x branch has been extended to the year 2020, I would strongly recommend that you start using Python 3.6 and above.
  • Why hold on to the past, unless you really have to?
    Here is a link to the Python Enhancement Proposal (PEP) 373 that refers to the EOL of Python 2: https://www.python.org/dev/peps/pep-0373/

How to do it...

Here are the four lines of First_GUI.py required to create the resulting GUI:

Execute this code and admire the result:

How it works...

In line nine, we import the built-in tkinter module and alias it as tk to simplify our Python code. In line 12, we create an instance of the Tk class by calling its constructor (the parentheses appended to Tk turns the class into an instance). We are using the alias tk, so we don't have to use the longer word tkinter. We are assigning the class instance to a variable named win (short for a window). As Python is a dynamically typed language, we did not have to declare this variable before assigning to it, and we did not have to give it a specific type. Python infers the type from the assignment of this statement. Python is a strongly typed language, so every variable always has a type. We just don't have to specify its type beforehand like in other languages. This makes Python a very powerful and productive language to program in.

A little note about classes and types:

  • In Python, every variable always has a type. We cannot create a variable that does not have a type. Yet, in Python, we do not have to declare the type beforehand, as we have to do in the C programming language.
  • Python is smart enough to infer the type. C#, at the time of writing this book, also has this capability.
    Using Python, we can create our own classes using the class keyword instead of the def keyword.
  • In order to assign the class to a variable, we first have to create an instance of our class. We create the instance and assign this instance to our variable, for example:
    class AClass(object):
        print('Hello from AClass') 
    class_instance = AClass()

    Now, the variable, class_instance, is of the AClass type.
    If this sounds confusing, do not worry. We will cover OOP in the coming chapters.

In line 15, we use the instance variable (win) of the class to give our window a title via the title property. In line 20, we start the window's event loop by calling the mainloop method on the class instance, win. Up to this point in our code, we created an instance and set one property, but the GUI will not be displayed until we start the main event loop.

  • An event loop is a mechanism that makes our GUI work. We can think of it as an endless loop where our GUI is waiting for events to be sent to it. A button click creates an event within our GUI, or our GUI being resized also creates an event.
  • We can write all of our GUI code in advance and nothing will be displayed on the user's screen until we call this endless loop (win.mainloop() in the preceding code).
    The event loop ends when the user clicks the red X button or a widget that we have programmed to end our GUI. When the event loop ends, our GUI also ends.

There's more...

This recipe used a minimum amount of Python code to create our first GUI program. However, throughout this book we will use OOP when it makes sense.

Preventing the GUI from being resized

By default, a GUI created using tkinter can be resized. This is not always ideal. The widgets we place onto our GUI forms might end up being resized in an improper way, so in this recipe, we will learn how to prevent our GUI from being resized by the user of our GUI application.

Getting ready

How to do it...

We are preventing the GUI from being resized, look at:
GUI_not_resizable.py

Running the code creates this GUI:

How it works...

Line 18 prevents the Python GUI from being resized.

Running this code will result in a GUI similar to the one we created in the first recipe. However, the user can no longer resize it. Also, note how the maximize button in the toolbar of the window is grayed out.

Why is this important? Because once we add widgets to our form, resizing can make our GUI look not as good as we want it to be. We will add widgets to our GUI in the next recipes.

The resizable() method is of the Tk() class, and by passing in (False, False), we prevent the GUI from being resized. We can disable both the x and y dimensions of the GUI from being resized, or we can enable one or both dimensions by passing in True or any number other than zero. (True, False) would enable the x-dimension but prevent the y-dimension from being resized.

We also added comments to our code in preparation for the recipes contained in this book.

In visual programming IDEs such as Visual Studio .NET, C# programmers often do not think of preventing the user from resizing the GUI they developed in this language. This creates inferior GUIs. Adding this one line of Python code can make our users appreciate our GUI.

Adding a label to the GUI form

A label is a very simple widget that adds value to our GUI. It explains the purpose of the other widgets, providing additional information. This can guide the user to the meaning of an Entry widget, and it can also explain the data displayed by widgets without the user having to enter data into it.

Getting ready

We are extending the first recipeCreating our first Python GUI. We will leave the GUI resizable, so don't use the code from the second recipe (or comment the win.resizable line out).

How to do it...

In order to add a Label widget to our GUI, we will import the ttk module from tkinter. Please note the two import statements. Add the following code just above win.mainloop(), which is located at the bottom of the first and second recipes:

GUI_add_label.py

Running the code adds a label to our GUI:

How it works...

In line 10 of the preceding code, we import a separate module from the tkinter package. The ttk module has some advanced widgets that make our GUI look great. In a sense, ttk is an extension within the tkinter package.

We still need to import the tkinter package itself, but we have to specify that we now want to also use ttk from the tkinter package.

ttk stands for themed tk. It improves our GUI's look and feel.

Line 19 adds the label to the GUI, just before we call mainloop .

We pass our window instance into the ttk.Label constructor and set the text property. This becomes the text our Label will display.

We also make use of the grid layout manager, which we'll explore in much more depth in Chapter 2, Layout Management.

Note how our GUI suddenly got much smaller than in the previous recipes.

The reason why it became so small is that we added a widget to our form. Without a widget, the tkinter package uses a default size. Adding a widget causes optimization, which generally means using as little space as necessary to display the widget(s).

If we make the text of the label longer, the GUI will expand automatically. We will cover this automatic form size adjustment in a later recipe in Chapter 2, Layout Management.

There's more...

Try resizing and maximizing this GUI with a label and watch what happens.

Creating buttons and changing their text property

In this recipe, we will add a button widget, and we will use this button to change a property of another widget that is a part of our GUI. This introduces us to callback functions and event handling in a Python GUI environment.

Getting ready

How to do it...

We add a button that, when clicked, performs an action. In this recipe, we will update the label we added in the previous recipe as well as the text property of the button:

GUI_create_button_change_property.py

The following screenshot shows how our GUI looks before clicking the button:

After clicking the button, the color of the label changed and so did the text of the button, which can be seen as follows:

How it works...

In line 19, we assign the label to a variable, and in line 20, we use this variable to position the label within the form. We need this variable in order to change its properties in the click_me() function. By default, this is a module-level variable, so we can access it inside the function, as long as we declare the variable above the function that calls it.

Line 23 is the event handler that is invoked once the button gets clicked.

In line 29, we create the button and bind the command to the click_me() function.

GUIs are event-driven. Clicking the button creates an event. We bind what happens when this event occurs in the callback function using the command property of the ttk.Button widget. Notice how we do not use parentheses, only the name click_me.

We also change the text of the label to include red as, in the printed book, this might otherwise not be obvious. When you run the code, you can see that the color does indeed change.

Lines 20 and 30 both use the grid layout manager, which will be discussed in the following chapter. This aligns both the label and the button.

There's more...

We will continue to add more and more widgets to our GUI and we will make use of many built-in properties in the other recipes in the book.

Text box widgets

In tkinter, the typical one-line textbox widget is called Entry. In this recipe, we will add such an Entry widget to our GUI. We will make our label more useful by describing what the Entry widget is doing for the user.

Getting ready

This recipe builds upon the Creating buttons and changing their text property recipe.

How to do it...

Check out the following code:

GUI_textbox_widget.py

Now, our GUI looks like this:

After entering some text and clicking the button, there is the following change in the GUI:

How it works...

In line 24, we get the value of the Entry widget. We have not used OOP yet, so how come we can access the value of a variable that was not even declared yet?

Without using OOP classes, in Python procedural coding, we have to physically place a name above a statement that tries to use that name. So how come this works (it does)?

The answer is that the button click event is a callback function, and by the time the button is clicked by a user, the variables referenced in this function are known and do exist.

Life is good.

Line 27 gives our label a more meaningful name; for now, it describes the text box below it. We moved the button down next to the label to visually associate the two. We are still using the grid layout manager, which will be explained in more detail in Chapter 2, Layout Management.

Line 30 creates a variable, name. This variable is bound to the Entry widget and, in our click_me() function, we are able to retrieve the value of the Entry widget by calling get() on this variable. This works like a charm.

Now we see that while the button displays the entire text we entered (and more), the textbox Entry widget did not expand. The reason for this is that we hardcoded it to a width of 12 in line 31.

  • Python is a dynamically typed language and infers the type from the assignment. What this means is that if we assign a string to the name variable, it will be of the string type, and if we assign an integer to name, its type will be integer.
  • Using tkinter, we have to declare the name variable as the type tk.StringVar() before we can use it successfully. The reason is that tkinter is not Python. We can use it from Python, but it is not the same language.

Setting the focus to a widget and disabling widgets

While our GUI is nicely improving, it would be more convenient and useful to have the cursor appear in the Entry widget as soon as the GUI appears. Here we learn how to do this.

Getting ready

This recipe extends the previous recipe, Text box widgets.

How to do it...

Python is truly great. All we have to do to set the focus to a specific control when the GUI appears is call the focus() method on an instance of a tkinter widget we previously created. In our current GUI example, we assigned the ttk.Entry class instance to a variable named, name_entered. Now, we can give it the focus.

Place the following code just above the code which is located at the bottom of the module and which starts the main windows event loop, like we did in the previous recipes:

GUI_set_focus.py

If you get some errors, make sure you are placing calls to variables below the code where they are declared. We are not using OOP as of yet, so this is still necessary. Later, it will no longer be necessary to do this.

On a Mac, you might have to set the focus to the GUI window first before being able to set the focus to the Entry widget in this window.

Adding this one line (38) of Python code places the cursor in our text Entry widget, giving the text Entry widget the focus. As soon as the GUI appears, we can type into this text box without having to click it first.

Note how the cursor now defaults to residing inside the text Entry box.

We can also disable widgets. To do that, we will set a property on the widget. We can make the button disabled by adding this one line (37 below) of Python code to create the button:

After adding the preceding line of Python code, clicking the button no longer creates any action:

How it works...

This code is self-explanatory. We set the focus to one control and disable another widget. Good naming in programming languages helps to eliminate lengthy explanations. Later in this book, there will be some advanced tips on how to do this while programming at work or practicing our programming skills at home.

There's more...

Yes. This is only the first chapter. There is much more to come.

Combo box widgets

In this recipe, we will improve our GUI by adding drop-down combo boxes which can have initial default values. While we can restrict the user to only certain choices, we can also allow the user to type in whatever they wish.

Getting ready

This recipe extends the previous recipe, Setting the focus to a widget and disabling widgets.

How to do it...

We insert another column between the Entry widget and the Button widget using the grid layout manager. Here is the Python code:

GUI_combobox_widget.py

This code, when added to the previous recipes, creates the following GUI. Note how, in line 43 in the preceding code, we assigned a tuple with default values to the combo box. These values then appear in the drop-down box. We can also change them if we like (by typing in different values when the application is running):

How it works...

Line 40 adds a second label to match the newly created combo box (created in line 42). Line 41 assigns the value of the box to a variable of a special tkinter type StringVar, as we did in a previous recipe.

Line 44 aligns the two new controls (label and combobox) within our previous GUI layout, and line 45 assigns a default value to be displayed when the GUI first becomes visible. This is the first value of the number_chosen['values'] tuple, the string "1". We did not place quotes around our tuple of integers in line 43, but they got casted into strings because, in line 41, we declared the values to be of the tk.StringVar type.

The preceding screenshot shows the selection made by the user as 42. This value gets assigned to the number variable.

There's more...

If we want to restrict the user to only be able to select the values we have programmed into the Combobox, we can do that by passing the state property into the constructor. Modify line 42 as follows:

GUI_combobox_widget_readonly_plus_display_number.py

Now, users can no longer type values into the Combobox. We can display the value chosen by the user by adding the following line of code to our Button Click Event Callback function:

After choosing a number, entering a name, and then clicking the button, we get the following GUI result, which now also displays the number selected:

Creating a check button with different initial states

In this recipe, we will add three check button widgets, each with a different initial state.

Getting ready

This recipe extends the previous recipe, Combo box widgets.

How to do it...

We are creating three check button widgets that differ in their states. The first is disabled and has a check mark in it. The user cannot remove this check mark as the widget is disabled.

The second check button is enabled, and by default, has no check mark in it, but the user can click it to add a check mark.

The third check button is both enabled and checked by default. The users can uncheck and recheck the widget as often as they like. Look at the following code:

GUI_checkbutton_widget.py

Running the new code results in the following GUI:

How it works...

In lines 47, 52, and 57 we create three variables of the IntVar type. In the line following each of these variables, we create a Checkbutton, passing in these variables. They will hold the state of the Checkbutton (unchecked or checked). By default, that is either 0 (unchecked) or 1 (checked), so the type of the variable is a tkinter integer.

We place these Checkbutton widgets in our main window, so the first argument passed into the constructor is the parent of the widget, in our case, win. We give each Checkbutton widget a different label via its text property.

Setting the sticky property of the grid to tk.W means that the widget will be aligned to the west of the grid. This is very similar to Java syntax and it means that it will be aligned to the left. When we resize our GUI, the widget will remain on the left side and not be moved towards the center of the GUI.

Lines 49 and 59 place a checkmark into the Checkbutton widget by calling the select() method on these two Checkbutton class instances.

We continue to arrange our widgets using the grid layout manager, which will be explained in more detail in Chapter 2, Layout Management.

Using radio button widgets

In this recipe, we will create three tkinter Radiobutton widgets. We will also add some code that changes the color of the main form, depending upon which Radiobutton is selected.

Getting ready

This recipe extends the previous recipe, Creating a check button with different initial states.

How to do it...

We add the following code to the previous recipe:

GUI_radiobutton_widget.py

Running this code and selecting the Radiobutton named Gold creates the following window:

How it works...

In lines 75-77, we create some module-level global variables which we will use in the creation of each radio button as well as in the callback function that creates the action of changing the background color of the main form (using the instance variable win).

We are using global variables to make it easier to change the code. By assigning the name of the color to a variable and using this variable in several places, we can easily experiment with different colors. Instead of doing a global search-and-replace of a hardcoded string (which is prone to errors), we just need to change one line of code and everything else will work. This is known as the DRY principle, which stands for Don't Repeat Yourself. This is an OOP concept which we will use in the later recipes of the book.

The names of the colors we are assigning to the variables (COLOR1, COLOR2 ...) are tkinter keywords (technically, they are symbolic names). If we use names that are not tkinter color keywords, then the code will not work.

Line 80 is the callback function that changes the background of our main form (win) depending upon the user's selection.

In line 87 we create a tk.IntVar variable. What is important about this is that we create only one variable to be used by all three radio buttons. As can be seen from the screenshot, no matter which Radiobutton we select, all the others will automatically be unselected for us.

Lines 89 to 96 create the three radio buttons, assigning them to the main form, passing in the variable to be used in the callback function that creates the action of changing the background of our main window.

While this is the first recipe that changes the color of a widget, quite honestly, it looks a bit ugly. A large portion of the following recipes in this book explain how to make our GUI look truly amazing.

There's more...

Here is a small sample of the available symbolic color names that you can look up at the official tcl manual page at http://www.tcl.tk/man/tcl8.5/TkCmd/colors.htm.

Name Red Green Blue
alice blue 240 248 255
AliceBlue 240 248 255
Blue 0 0 255
Gold 255 215 0
Red 255 0 0

Some of the names create the same color, so alice blue creates the same color as AliceBlue. In this recipe, we used the symbolic names Blue, Gold, and Red.

Using scrolled text widgets

ScrolledText widgets are much larger than simple Entry widgets and span multiple lines. They are widgets like Notepad and wrap lines, automatically enabling vertical scrollbars when the text gets larger than the height of the ScrolledText widget.

Getting ready

How to do it...

By adding the following lines of code, we create a ScrolledText widget:

GUI_scrolledtext_widget.py

We can actually type into our widget, and if we type enough words, the lines will automatically wrap around:

Once we type in more words than the height the widget can display, the vertical scrollbar becomes enabled. This all works out-of-the-box without us needing to write any more code to achieve this:

How it works...

In line 11, we import the module that contains the ScrolledText widget class. Add this to the top of the module, just below the other two import statements.

Lines 100 and 101 define the width and height of the ScrolledText widget we are about to create. These are hardcoded values we are passing into the ScrolledText widget constructor in line 102.

These values are magic numbers found by experimentation to work well. You might experiment by changing scol_w from 30 to 50 and observe the effect!

In line 102, we are also  setting a property on the widget by passing in wrap=tk.WORD.

By setting the wrap property to tk.WORD we are telling the ScrolledText widget to break lines by words so that we do not wrap around within a word. The default option is tk.CHAR, which wraps any character regardless of whether we are in the middle of a word.

The second screenshot shows that the vertical scrollbar moved down because we are reading a longer text that does not entirely fit into the x, y dimensions of the SrolledText control we created.

Setting the columnspan property of the grid widget to 3 for the SrolledText widget makes this widget span all the three columns. If we do not set this property, our SrolledText widget would only reside in column one, which is not what we want.

Adding several widgets in a loop

So far, we have created several widgets of the same type (for example, Radiobutton) by basically copying and pasting the same code and then modifying the variations (for example, the column number). In this recipe, we start refactoring our code to make it less redundant.

Getting ready

We are refactoring some parts of the previous recipe's code, Using scrolled text widgets, so you need that code to apply this recipe to.

How to do it...

Here's how we refactor our code:

GUI_adding_widgets_in_loop.py

Running this code will create the same window as before, but our code is much cleaner and easier to maintain. This will help us when we expand our GUI in the coming recipes.

How it works...

In line 77, we have turned our global variables into a list.

In line 89, we set a default value to the tk.IntVar variable that we named radVar. This is important because, while in the previous recipe we had set the value for Radiobutton widgets starting at 1, in our new loop it is much more convenient to use Python's zero-based indexing. If we did not set the default value to a value outside the range of our Radiobutton widgets, one of the radio buttons would be selected when the GUI appears. While this in itself might not be so bad, it would not trigger the callback and we would end up with a radio button selected that does not do its job (that is, change the color of the main win form).

In line 95, we replace the three previously hardcoded creations of the Radiobutton widgets with a loop that does the same. It is just more concise (fewer lines of code) and much more maintainable. For example, if we want to create 100 instead of just three Radiobutton widgets, all we have to change is the number inside Python's range operator. We would not have to type or copy and paste 97 sections of duplicate code, just one number.

Line 82 shows the modified callback function.

There's more...

This recipe concludes the first chapter of this book. All the following recipes in all of the next chapters will build upon the GUI we have constructed so far, greatly enhancing it.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Use object-oriented programming to develop amazing GUIs in Python
  • Create a working GUI project as a central resource for developing your Python GUIs
  • Easy-to-follow recipes to help you develop code using the latest released version of Python

Description

Python is a multi-domain, interpreted programming language. It is a widely used general-purpose, high-level programming language. It is often used as a scripting language because of its forgiving syntax and compatibility with a wide variety of different eco-systems. Python GUI Programming Cookbook follows a task-based approach to help you create beautiful and very effective GUIs with the least amount of code necessary. This book will guide you through the very basics of creating a fully functional GUI in Python with only a few lines of code. Each and every recipe adds more widgets to the GUIs we are creating. While the cookbook recipes all stand on their own, there is a common theme running through all of them. As our GUIs keep expanding, using more and more widgets, we start to talk to networks, databases, and graphical libraries that greatly enhance our GUI’s functionality. This book is what you need to expand your knowledge on the subject of GUIs, and make sure you’re not missing out in the long run.

Who is this book for?

This book is for intermediate Python programmers who wish to enhance their Python skills by writing powerful GUIs in Python. As Python is such a great and easy to learn language, this book is also ideal for any developer with experience of other languages and enthusiasm to expand their horizon.

What you will learn

  • Create the GUI Form and add widgets
  • Arrange the widgets using layout managers
  • Use object-oriented programming to create GUIs
  • Create Matplotlib charts
  • Use threads and talking to networks
  • Talk to a MySQL database via the GUI
  • Perform unit-testing and internationalizing the GUI
  • Extend the GUI with third-party graphical libraries
  • Get to know the best practices to create GUIs

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 29, 2017
Length: 444 pages
Edition : 2nd
Language : English
ISBN-13 : 9781787129023
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want

Product Details

Publication date : May 29, 2017
Length: 444 pages
Edition : 2nd
Language : English
ISBN-13 : 9781787129023
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Mex$85 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Mex$ 3,036.97
Daniel Arbuckle???s Mastering Python
Mex$902.99
Python Data Structures and Algorithms
Mex$1004.99
Python GUI Programming Cookbook, Second Edition
Mex$1128.99
Total Mex$ 3,036.97 Stars icon

Table of Contents

11 Chapters
Creating the GUI Form and Adding Widgets Chevron down icon Chevron up icon
Layout Management Chevron down icon Chevron up icon
Look and Feel Customization Chevron down icon Chevron up icon
Data and Classes Chevron down icon Chevron up icon
Matplotlib Charts Chevron down icon Chevron up icon
Threads and Networking Chevron down icon Chevron up icon
Storing Data in our MySQL Database via our GUI Chevron down icon Chevron up icon
Internationalization and Testing Chevron down icon Chevron up icon
Extending Our GUI with the wxPython Library Chevron down icon Chevron up icon
Creating Amazing 3D GUIs with PyOpenGL and PyGLet Chevron down icon Chevron up icon
Best Practices Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.4
(5 Ratings)
5 star 20%
4 star 20%
3 star 40%
2 star 20%
1 star 0%
Zthou Jan 23, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Essendo ipovedente gravissimo adoro le pubblicazioni in formato Kindle che oltre a tutti gli altri vantaggi mi consentono di leggere su grande schermo ed a colori invertiti qualsiasi testo.Non essendo uno scripter phyton questa collezzione mi consente di sviluppare soluzioni pronte per i miei piccoli progetti per cui l'uso del computer e l'automazione sono indispensabili
Amazon Verified review Amazon
B. Williams Apr 15, 2018
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
This is strictly a tkinter tutorial, not a reference book. It begins with the most basic information and then moves on from there. If you have been trying to learn tkinter and you are pulling your hair out trying to pick up bits and pieces from the Internet, get this book, start with chapter 1, and work through it. I wish I had done that a couple of weeks ago!The most aggravating thing about the book is that it only shows bits and pieces of the code, but you can download all the code and follow along in your favorite editor. (The correct address for download is given on page 12; earlier instructions on page 4 are wrong.)
Amazon Verified review Amazon
K Feb 09, 2018
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Not what I had hoped for, but can't say that it was a complete waste of time - I'll admit that I picked up a few things from the book/author but not enough to justify a $25+ price tag.The book is essentially a series of1) A Topic Title2) 2, maybe 3 sentences explaining the topic3) A "Getting ready" section w/ a few sentences providing an overview of what will be done.(Here, you could try to come up w/ a solution on your own before seeing the author's solution)4) A "How to do it" section consisting of 1 or so pages of code (there isn't a single program in this book, just snippets that will run)5) A "How it works" section w/ 2, maybe 3 small paragraphs (sentences in some cases) somewhat briefly brushing over the codeREPEAT W/ ANOTHER TOPICI've done some GUI programming in college classes so I had an idea as to how objects are added and how classes are constructed, and so on. I was expecting to see introduction-type material in the beginning, but hoping for advanced topics/examples or in-depth explanations towards the end. That didn't happen.This is more of a "Get Started Quickly w/ tkinter" type book than anything else: Read this, understand what is possible and understand just enough of how tkinter works so you can work with the official documentation.This book could have been 1/3 shorter. I read the first few chapters w/ care and skimmed through the rest b/c I got bored w/ the repetitiveness. DRY was certainly not taken into account as there is a lot of needless repetition (filler). It could have done w/out the Testing information and all of chapter 11. These are very important topics and they deserve a thorough explanation, which this book did not offer. The way it was included in the book was pointless and a disservice to readers.
Amazon Verified review Amazon
A. Carter Dec 28, 2017
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
Not really a cookbook. It's more of a tutorial. All the code is written in short snippets, so if you want to build anything you have to keep going back to previous chapters. I was hoping for a reference book for Tkinter widgets, that is not this book. Author does not go into very many widgets and the ones he does talk about are incomplete. At one point he states that the canvas widget is really cool and you should go on line and research what it does! That is what I thought the book was for. If I go online why do I need this book. Author does seem knowledgeable and I did learn some things from this book. I don't think I will ever go back to this book as a reference.
Amazon Verified review Amazon
stan kulikowski Jul 28, 2019
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
this text shows us how to construct an empty GUI that does nothing except demonstrate how the devices operate. i would call this a sampler (which shows that a device a works) but not a cookbook (which ought to supply short recipes of devices actually doing something useful). at the end of these exercises we have a complex piece of code in which most of the graphic user devices are shown as examples, but it is difficult to extract that section of code to employ in some other program which needs this function for some other purpose.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.