Python GUI Programming with Tkinter
eBook - ePub

Python GUI Programming with Tkinter

Design and build functional and user-friendly GUI applications, 2nd Edition

Alan D. Moore

Condividi libro
  1. 664 pagine
  2. English
  3. ePUB (disponibile sull'app)
  4. Disponibile su iOS e Android
eBook - ePub

Python GUI Programming with Tkinter

Design and build functional and user-friendly GUI applications, 2nd Edition

Alan D. Moore

Dettagli del libro
Anteprima del libro
Indice dei contenuti
Citazioni

Informazioni sul libro

Transform your evolving user requirements into feature-rich Tkinter applications

Key Features

  • Extensively revised with new content on RESTful networking, classes in Tkinter, and the Notebook widget
  • Take advantage of Tkinter's lightweight, portable, and easy-to-use features
  • Build better-organized code and learn to manage an evolving codebase

Book Description

Tkinter is widely used to build GUIs in Python due to its simplicity. In this book, you'll discover Tkinter's strengths and overcome its challenges as you learn to develop fully featured GUI applications.

Python GUI Programming with Tkinter, Second Edition, will not only provide you with a working knowledge of the Tkinter GUI library, but also a valuable set of skills that will enable you to plan, implement, and maintain larger applications. You'll build a full-blown data entry application from scratch, learning how to grow and improve your code in response to continually changing user and business needs.

You'll develop a practical understanding of tools and techniques used to manage this evolving codebase and go beyond the default Tkinter widget capabilities. You'll implement version control and unit testing, separation of concerns through the MVC design pattern, and object-oriented programming to organize your code more cleanly.

You'll also gain experience with technologies often used in workplace applications, such as SQL databases, network services, and data visualization libraries. Finally, you'll package your application for wider distribution and tackle the challenge of maintaining cross-platform compatibility.

What you will learn

  • Produce well-organized, functional, and responsive GUI applications
  • Extend the functionality of existing widgets using classes and OOP
  • Plan wisely for the expansion of your app using MVC and version control
  • Make sure your app works as intended through widget validation and unit testing
  • Use tools and processes to analyze and respond to user requests
  • Become familiar with technologies used in workplace applications, including SQL, HTTP, Matplotlib, threading, and CSV
  • Use PostgreSQL authentication to ensure data security for your application

Who this book is for

This book is for programmers who understand the syntax of Python, but do not yet have the skills, techniques, and knowledge to design and implement a complete software application. A fair grasp of basic Python syntax is required.

Domande frequenti

Come faccio ad annullare l'abbonamento?
È semplicissimo: basta accedere alla sezione Account nelle Impostazioni e cliccare su "Annulla abbonamento". Dopo la cancellazione, l'abbonamento rimarrà attivo per il periodo rimanente già pagato. Per maggiori informazioni, clicca qui
È possibile scaricare libri? Se sì, come?
Al momento è possibile scaricare tramite l'app tutti i nostri libri ePub mobile-friendly. Anche la maggior parte dei nostri PDF è scaricabile e stiamo lavorando per rendere disponibile quanto prima il download di tutti gli altri file. Per maggiori informazioni, clicca qui
Che differenza c'è tra i piani?
Entrambi i piani ti danno accesso illimitato alla libreria e a tutte le funzionalità di Perlego. Le uniche differenze sono il prezzo e il periodo di abbonamento: con il piano annuale risparmierai circa il 30% rispetto a 12 rate con quello mensile.
Cos'è Perlego?
Perlego è un servizio di abbonamento a testi accademici, che ti permette di accedere a un'intera libreria online a un prezzo inferiore rispetto a quello che pagheresti per acquistare un singolo libro al mese. Con oltre 1 milione di testi suddivisi in più di 1.000 categorie, troverai sicuramente ciò che fa per te! Per maggiori informazioni, clicca qui.
Perlego supporta la sintesi vocale?
Cerca l'icona Sintesi vocale nel prossimo libro che leggerai per verificare se è possibile riprodurre l'audio. Questo strumento permette di leggere il testo a voce alta, evidenziandolo man mano che la lettura procede. Puoi aumentare o diminuire la velocità della sintesi vocale, oppure sospendere la riproduzione. Per maggiori informazioni, clicca qui.
Python GUI Programming with Tkinter è disponibile online in formato PDF/ePub?
Sì, puoi accedere a Python GUI Programming with Tkinter di Alan D. Moore in formato PDF e/o ePub, così come ad altri libri molto apprezzati nelle sezioni relative a Computer Science e Programming in Python. Scopri oltre 1 milione di libri disponibili nel nostro catalogo.

Informazioni

Anno
2021
ISBN
9781801818865
Edizione
2

9

Improving the Look with Styles and Themes

While programs can be perfectly functional with plain text in shades of black, white, and gray, the subtle use of colors, fonts, and images can enhance the visual appeal and usability of even the most utilitarian applications. Your data entry application is no exception, and the current round of requests brought to you by your coworkers seems to require some retooling of the application's look and feel.
Specifically, you've been asked to address these points:
  • Your manager has informed you that ABQ's corporate policy requires the company logo to be displayed on all in-house software. You've been provided with a corporate logo image to include in the application.
  • The data entry staff have some readability issues with the form. They want more visual distinction between the sections of the form and more visibility for error messages.
  • The data entry staff have also requested that you highlight records they've added or updated during a session to help them keep track of their work.
In addition to the user's requests, you'd like to make your application look more professional by adding some icons to your buttons and menu.
In this chapter, we're going to learn about some features of Tkinter that will help us to solve these issues:
  • In Working with images in Tkinter, we'll learn how to add pictures and icons to our Tkinter GUI.
  • In Styling Tkinter widgets, we'll learn how to adjust the colors and visual style of Tkinter widgets, both directly and using tags.
  • In Working with fonts in Tkinter, we'll learn the ins and outs of using fonts in Tkinter.
  • In Styling Ttk widgets, we'll learn how to adjust the look of Ttk widgets using styles and themes.

Working with images in Tkinter

To solve the corporate logo issue and spruce up our application with some icons, we're going to need to understand how to work with images in Tkinter. Tkinter provides access to image files through two classes: the PhotoImage class and the BitmapImage class. Let's see how these classes can help us add graphics to our application.

Tkinter PhotoImage

Many Tkinter widgets, including Label and Button, accept an image argument that allows us to display an image on the widget. This argument requires that we create and pass in a PhotoImage (or BitmapImage) object.
Making a PhotoImage object is fairly simple:
myimage = tk.PhotoImage(file='my_image.png') 
PhotoImage is typically called with the keyword argument file, which is pointed to a file path. Alternatively, you can use the data argument to point to a bytes object containing image data. In either case, the resulting object can now be used wherever an image argument is accepted, such as in a Label widget:
mylabel = tk.Label(root, image=myimage) 
Note that if we pass both an image and text argument to the Label initializer, only the image will be displayed by default. To display both, we need to also provide a value for the compound argument, which determines how the image and text will be arranged with respect to one another. For example:
mylabel_1 = tk.Label(root, text='Banana', image=myimage) mylabel_2 = tk.Label( root, text='Plantain', image=myimage, compound=tk.LEFT ) 
In this situation, the first label would only show the image; the text will not be displayed. In the second, since we have specified a compound value of tk.LEFT, the image will be displayed to the left of the text. compound can be any of LEFT, RIGHT, BOTTOM, or TOP (either lowercase strings or the Tkinter constants), and indicates where the image will be placed in relation to the text.

PhotoImage and variable scope

When using a PhotoImage object, it is critical to remember that your application must retain a reference to the object that will stay in scope for as long as the image is shown; otherwise, the image will not appear. To understand what this means, consider the following example:
# image_scope_demo.py import tkinter as tk class App(tk.Tk): def __init__(self): super().__init__() smile = tk.PhotoImage(file='smile.gif') tk.Label(self, image=smile).pack() App().mainloop() 
If you run this example, you'll notice that no image gets displayed. That's because the variable holding the PhotoImage object, smile, is a local variable, and therefore destroyed as soon as the initializer returns. With no reference remaining to the PhotoImage object, it is discarded and the image vanishes, ...

Indice dei contenuti