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

Compartir libro
  1. 664 páginas
  2. English
  3. ePUB (apto para móviles)
  4. Disponible en iOS y Android
eBook - ePub

Python GUI Programming with Tkinter

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

Alan D. Moore

Detalles del libro
Vista previa del libro
Índice
Citas

Información del 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.

Preguntas frecuentes

¿Cómo cancelo mi suscripción?
Simplemente, dirígete a la sección ajustes de la cuenta y haz clic en «Cancelar suscripción». Así de sencillo. Después de cancelar tu suscripción, esta permanecerá activa el tiempo restante que hayas pagado. Obtén más información aquí.
¿Cómo descargo los libros?
Por el momento, todos nuestros libros ePub adaptables a dispositivos móviles se pueden descargar a través de la aplicación. La mayor parte de nuestros PDF también se puede descargar y ya estamos trabajando para que el resto también sea descargable. Obtén más información aquí.
¿En qué se diferencian los planes de precios?
Ambos planes te permiten acceder por completo a la biblioteca y a todas las funciones de Perlego. Las únicas diferencias son el precio y el período de suscripción: con el plan anual ahorrarás en torno a un 30 % en comparación con 12 meses de un plan mensual.
¿Qué es Perlego?
Somos un servicio de suscripción de libros de texto en línea que te permite acceder a toda una biblioteca en línea por menos de lo que cuesta un libro al mes. Con más de un millón de libros sobre más de 1000 categorías, ¡tenemos todo lo que necesitas! Obtén más información aquí.
¿Perlego ofrece la función de texto a voz?
Busca el símbolo de lectura en voz alta en tu próximo libro para ver si puedes escucharlo. La herramienta de lectura en voz alta lee el texto en voz alta por ti, resaltando el texto a medida que se lee. Puedes pausarla, acelerarla y ralentizarla. Obtén más información aquí.
¿Es Python GUI Programming with Tkinter un PDF/ePUB en línea?
Sí, puedes acceder a Python GUI Programming with Tkinter de Alan D. Moore en formato PDF o ePUB, así como a otros libros populares de Computer Science y Programming in Python. Tenemos más de un millón de libros disponibles en nuestro catálogo para que explores.

Información

Año
2021
ISBN
9781801818865
Edición
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, ...

Índice