Movatterモバイル変換


[0]ホーム

URL:


Packt
Search iconClose icon
Search icon CANCEL
Subscription
0
Cart icon
Your Cart(0 item)
Close icon
You have no products in your basket yet
Save more on your purchases!discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Profile icon
Account
Close icon

Change country

Modal Close icon
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timerSALE ENDS IN
0Days
:
00Hours
:
00Minutes
:
00Seconds
Home> Programming> GUI Application Development> Python GUI Programming Cookbook, Second Edition
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
€8.98€32.99
Full star iconFull star iconFull star iconHalf star iconEmpty star icon3.4(5 Ratings)
eBookMay 2017444 pages2nd Edition
eBook
€8.98 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€8.98 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
Product feature iconAI Assistant (beta) to help accelerate your learning

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Table of content iconView table of contentsPreview book icon Preview Book

Python GUI Programming Cookbook, Second Edition

Introduction


In this chapter, we will explore how to arrange widgets within widgets to create our Python GUI. Learning the fundamentals of GUI layout design will enable us to create great-looking GUIs. There are certain techniques that will help us in achieving this layout design.

The grid layout manager is one of the most important layout tools built into tkinter that we will be using.

We can very easily create menu bars, tabbed controls (aka Notebooks), and many more widgets using tkinter.

Here is an overview of the Python modules used in this chapter:

Arranging several labels within a label frame widget


The LabelFrame widget allows us to design our GUI in an organized fashion. We are still using the grid layout manager as our main layout design tool, but by usingLabelFrame widgets, we get much more control over our GUI design.

Getting ready

We will start adding more and more widgets to our GUI, and we will make the GUI fully functional in the coming recipes. Here, we will start using theLabelFrame widget. We will reuse the GUI from the recipe, Adding Several Widgets in a Loop in  Chapter 1,Creating the GUI Form and Adding Widgets.

How to do it…

Add the following code just above the main event loop towards the bottom of the Python module:

GUI_LabelFrame_column_one.py

Running the code will result in the GUI looking as follows:

Note

Uncomment line 111 and notice the different alignment of LabelFrame.

We can easily align the labels vertically by changing our code, as shown in the next screenshot:

Note

Note that the only change we had to make was...

Using padding to add space around widgets


Our GUI is being created nicely. Next, we will improve the visual aspects of our widgets by adding a little space around them, so they can breathe.

Getting ready

While tkinter might have had a reputation for creating ugly GUIs, this has dramatically changed since version 8.5. You just have to know how to use the tools and techniques that are available. That's what we will do next.

Note

tkinter version 8.6 ships with Python 3.6.

How to do it…

The procedural way of adding spacing around widgets is shown first, and then we will use a loop to achieve the same thing in a much better way.

OurLabelFrame looks a bit tight as it blends into the main window towards the bottom. Let's fix this now.

Modify line 110 of the code snippet from GUI_LabelFrame_column_one.py in the previous recipe by addingpadx andpady. You can also find the code in: 

GUI_add_padding.py

Now, ourLabelFrame gets some breathing space:

How it works…

In tkinter, adding space horizontally and vertically...

How widgets dynamically expand the GUI


You may have noticed in the previous screenshots and by running the code that the widgets have the capability of extending themselves to the space they need in order to visually display their text.

Note

  • Java introduced the concept of dynamic GUI layout management. In comparison, visual development IDEs, such as VS.NET, lay out the GUI in a visual manner, and basically hardcode thex andy coordinates of the UI elements.
  • Usingtkinter, this dynamic capability creates both an advantage and a little bit of a challenge because sometimes our GUI dynamically expands when we would rather it not be so dynamic! Well, we are dynamic Python programmers, so we can figure out how to make the best use of this fantastic behavior!

Getting ready

In the beginning of the previous recipe,Using padding to add space around widgets, we added aLabelFrame widget. This moved some of our controls to the center of column0. We might not want this modification in our GUI layout. Next...

Left arrow icon

Page1 of 9

Right arrow icon
Download code iconDownload 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 :

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
Product feature iconAI Assistant (beta) to help accelerate your learning

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99billed monthly
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconSimple pricing, no contract
€189.99billed annually
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick iconExclusive print discounts
€264.99billed in 18 months
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick iconExclusive print discounts

Frequently bought together


Python GUI Programming Cookbook, Second Edition
Python GUI Programming Cookbook, Second Edition
Read more
May 2017444 pages
Full star icon3.4 (5)
eBook
eBook
€8.98€32.99
€41.99
Python Data Structures and Algorithms
Python Data Structures and Algorithms
Read more
May 2017310 pages
Full star icon2.7 (11)
eBook
eBook
€8.98€29.99
€36.99
Daniel Arbuckle???s Mastering Python
Daniel Arbuckle???s Mastering Python
Read more
Jun 2017274 pages
Full star icon5 (1)
eBook
eBook
€8.98€26.99
€32.99
Stars icon
Total111.97
Python GUI Programming Cookbook, Second Edition
€41.99
Python Data Structures and Algorithms
€36.99
Daniel Arbuckle???s Mastering Python
€32.99
Total111.97Stars icon
Buy 2+ to unlock€6.99 prices - master what's next.
SHOP NOW

Table of Contents

11 Chapters
Creating the GUI Form and Adding WidgetsChevron down iconChevron up icon
Creating the GUI Form and Adding Widgets
Introduction
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
Layout ManagementChevron down iconChevron up icon
Layout Management
Introduction
Arranging several labels within a label frame widget
Using padding to add space around widgets
How widgets dynamically expand the GUI
Aligning the GUI widgets by embedding frames within frames
Creating menu bars
Creating tabbed widgets
Using the grid layout manager
Look and Feel CustomizationChevron down iconChevron up icon
Look and Feel Customization
Introduction
Creating message boxes - information, warning, and error
How to create independent message boxes
How to create the title of a tkinter window form
Changing the icon of the main root window
Using a spin box control
Relief, sunken and raised appearance of widgets
Creating tooltips using Python
Adding a progressbar to the GUI
How to use the canvas widget
Data and ClassesChevron down iconChevron up icon
Data and Classes
Introduction
How to use StringVar()
How to get data from a widget
Using module-level global variables
How coding in classes can improve the GUI
Writing callback functions
Creating reusable GUI components
Matplotlib ChartsChevron down iconChevron up icon
Matplotlib Charts
Introduction
Creating beautiful charts using Matplotlib
Installing Matplotlib using pip with whl extension
Creating our first chart
Placing labels on charts
How to give the chart a legend
Scaling charts
Adjusting the scale of charts dynamically
Threads and NetworkingChevron down iconChevron up icon
Threads and Networking
Introduction
How to create multiple threads
Starting a thread
Stopping a thread
How to use queues
Passing queues among different modules
Using dialog widgets to copy files to your network
Using TCP/IP to communicate via networks
Using urlopen to read data from websites
Storing Data in our MySQL Database via our GUIChevron down iconChevron up icon
Storing Data in our MySQL Database via our GUI
Introduction
Installing and connecting to a MySQL server from Python
Configuring the MySQL database connection
Designing the Python GUI database
Using the SQL INSERT command
Using the SQL UPDATE command
Using the SQL DELETE command
Storing and retrieving data from our MySQL database
Using the MySQL workbench
Internationalization and TestingChevron down iconChevron up icon
Internationalization and Testing
Introduction
Displaying widget text in different languages
Changing the entire GUI language, all at once
Localizing the GUI
Preparing the GUI for internationalization
How to design a GUI in an agile fashion
Do we need to test the GUI code?
Setting debug watches
Configuring different debug output levels
Creating self-testing code using Python's __main__ section
Creating robust GUIs using unit tests
How to write unit tests using the Eclipse PyDev IDE
Extending Our GUI with the wxPython LibraryChevron down iconChevron up icon
Extending Our GUI with the wxPython Library
Introduction
Installing the wxPython library
Creating our GUI in wxPython
Quickly adding controls using wxPython
Trying to embed a main wxPython app in a main tkinter app
Trying to embed our tkinter GUI code into wxPython
Using Python to control two different GUI frameworks
Communicating between the two connected GUIs
Creating Amazing 3D GUIs with PyOpenGL and PyGLetChevron down iconChevron up icon
Creating Amazing 3D GUIs with PyOpenGL and PyGLet
Introduction
PyOpenGL transforms our GUI
Our GUI in 3D!
Using bitmaps to make our GUI pretty
PyGLet transforms our GUI easier than PyOpenGL
Our GUI in amazing colors
OpenGL animation
Creating a slide show using tkinter
Best PracticesChevron down iconChevron up icon
Best Practices
Introduction
Avoiding spaghetti code
Using __init__ to connect modules
Mixing fall-down and OOP coding
Using a code naming convention
When not to use OOP
How to use design patterns successfully
Avoiding complexity
GUI design using multiple notebooks

Recommendations for you

Left arrow icon
Debunking C++ Myths
Debunking C++ Myths
Read more
Dec 2024226 pages
Full star icon5 (1)
eBook
eBook
€8.98€23.99
€29.99
Go Recipes for Developers
Go Recipes for Developers
Read more
Dec 2024350 pages
eBook
eBook
€8.98€23.99
€29.99
50 Algorithms Every Programmer Should Know
50 Algorithms Every Programmer Should Know
Read more
Sep 2023538 pages
Full star icon4.5 (64)
eBook
eBook
€8.98€29.99
€37.99
€37.99
Asynchronous Programming with C++
Asynchronous Programming with C++
Read more
Nov 2024424 pages
Full star icon5 (1)
eBook
eBook
€8.98€25.99
€31.99
Modern CMake for C++
Modern CMake for C++
Read more
May 2024504 pages
Full star icon4.7 (13)
eBook
eBook
€8.98€29.99
€37.99
Learn Python Programming
Learn Python Programming
Read more
Nov 2024616 pages
Full star icon3.5 (2)
eBook
eBook
€8.98€23.99
€29.99
Learn to Code with Rust
Learn to Code with Rust
Read more
Sep 202557hrs 40mins
Full star icon5 (1)
Video
Video
€8.98€56.99
Modern Python Cookbook
Modern Python Cookbook
Read more
Jul 2024818 pages
Full star icon4.9 (17)
eBook
eBook
€8.98€32.99
€41.99
Right arrow icon

Customer reviews

Rating distribution
Full star iconFull star iconFull star iconHalf star iconEmpty star icon3.4
(5 Ratings)
5 star20%
4 star20%
3 star40%
2 star20%
1 star0%
ZthouJan 23, 2019
Full star iconFull star iconFull star iconFull star iconFull star icon5
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 reviewAmazon
B. WilliamsApr 15, 2018
Full star iconFull star iconFull star iconFull star iconEmpty star icon4
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 reviewAmazon
KFeb 09, 2018
Full star iconFull star iconFull star iconEmpty star iconEmpty star icon3
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 reviewAmazon
A. CarterDec 28, 2017
Full star iconFull star iconFull star iconEmpty star iconEmpty star icon3
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 reviewAmazon
stan kulikowskiJul 28, 2019
Full star iconFull star iconEmpty star iconEmpty star iconEmpty star icon2
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 reviewAmazon

People who bought this also bought

Left arrow icon
50 Algorithms Every Programmer Should Know
50 Algorithms Every Programmer Should Know
Read more
Sep 2023538 pages
Full star icon4.5 (64)
eBook
eBook
€8.98€29.99
€37.99
€37.99
Event-Driven Architecture in Golang
Event-Driven Architecture in Golang
Read more
Nov 2022384 pages
Full star icon4.9 (10)
eBook
eBook
€8.98€29.99
€37.99
€33.99
The Python Workshop Second Edition
The Python Workshop Second Edition
Read more
Nov 2022600 pages
Full star icon4.6 (19)
eBook
eBook
€8.98€31.99
€38.99
Template Metaprogramming with C++
Template Metaprogramming with C++
Read more
Aug 2022480 pages
Full star icon4.6 (13)
eBook
eBook
€8.98€28.99
€35.99
Domain-Driven Design with Golang
Domain-Driven Design with Golang
Read more
Dec 2022204 pages
Full star icon4.4 (18)
eBook
eBook
€8.98€26.99
€33.99
Right arrow icon

About the author

Profile icon Burkhard Meier
Burkhard Meier
Burkhard Meier is a professional software test automation designer, developer, and analyst. He has more than 17 years' professional experience working for several software companies in California, USA.He is the author of Python GUI Programming Cookbook, First and Second Edition. This book is also available as a Packt video course.He is also the author of the Python Projects Packt video course.In his professional career, he developed advanced in-house testing frameworks written in Python 3. He also developed advanced test automation GUIs in Python, which highly increased the productivity of the software development testing team.When not dreaming in Python code, he reads programming books about design, likes to go for long walks, and reads classical poetry.
Read more
See other products by Burkhard Meier
Getfree 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 iconChevron 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 iconChevron 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 iconChevron 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 iconChevron 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 iconChevron 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 iconChevron 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.

Create a Free Account To Continue Reading

Modal Close icon
OR
    First name is required.
    Last name is required.

The Password should contain at least :

  • 8 characters
  • 1 uppercase
  • 1 number
Notify me about special offers, personalized product recommendations, and learning tips By signing up for the free trial you will receive emails related to this service, you can unsubscribe at any time
By clicking ‘Create Account’, you are agreeing to ourPrivacy Policy andTerms & Conditions
Already have an account? SIGN IN

Sign in to activate your 7-day free access

Modal Close icon
OR
By redeeming the free trial you will receive emails related to this service, you can unsubscribe at any time.

[8]ページ先頭

©2009-2025 Movatter.jp