Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Python is an interpreted, general-purpose, high-level programming language that is very popular among developers and professionals because of its vast library of addon modules. It is a platform-independent scripted language that is supported by many individuals as an open-source project. The fact that it is freely available and runs on all platforms makes it ever more popular.
The goal of Introduction to Python Programming and Developing GUI Applications with PyQT is to teach the Python programming language through practical examples. Whether you are new to computers or are an experienced programmer, this book is intended to help you develop your programming skills. It is written with the requirements of all levels in mind—developers, professionals, and beginners. The book begins with a solid introduction of Python from scratch—loops, control structures, sequences, functions, classes, and exception handling. Thereafter, the book explains persistence through file handling and targets developers by introducing GUI application development in PyQT.
As you read through the book, you will acquire the skills needed for building practical Python programming applications and will learn how these skills can be put into use in real-world scenarios.
Like any good book, Introduction to Python Programming explains the more basic concepts, one step at a time, by writing small programs to demonstrate each step. Gradually, once the reader is acquainted with logical blocks, the book explains using the blocks for understanding more complex concepts. By the time you finish the book, you will understand how to break problems down into manageable chunks, and then refine your code into applications.
This book starts with a discussion of Python’s basics, beginning with easy examples, and then gradually going deeper to uncover the more complex topics of GUI programming in Python. By the end of the book, readers will also have an understanding of using back-end databases for storing and fetching information.
Chapter 1, “Python and its Features”: In this chapter, you will have a detailed introduction to Python and its features, such as installing Python on different platforms, interacting with Python through Command Line mode and the IDLE IDE. You will also learn to write your first Python program. The chapter also introduces the Python basics, like its different data types, literals, variables, and keywords. Finally, the chapter explains how to write comments, continuation lines, and print messages.
Chapter 2, “Getting Wet in Python”: In this chapter, you will learn to apply arithmetic operations and different logical and membership operators in Python programs. You will see the use of escape sequences. You will learn to get data from the user as well as process incoming data. You will also see how to convert data into different types, learn to display octal and hexa values, perform bitwise operations, and use complex numbers. You will also learn how to use the if...else statement in making decisions. Finally, the chapter explains how to use while and for loops for doing repetitive tasks.
Chapter 3, “Sequences”: This chapter focuses on using different containers. You will learn to perform different operations on strings, including concatenating strings, splitting strings, and then converting them into different cases, such as uppercase, title case, and lowercase, etc. Also, you will learn to do list slicing, searching elements in tuples, and performing operations on sets, such as finding their union, intersection, and differences. You will learn how key/value pairs are maintained in a dictionary and how to append, delete, or and modify key/value pairs. Finally, the chapter explains how to create one- and two-dimensional arrays.
Chapter 4, “Functions and Modules”: In this chapter, you will learn about different statements that define and return values from functions. Also, you will learn to use default value parameters and keyword arguments in a function, as well as use local and global variables. The chapter explains how to create lambda functions for smaller expressions. Also, you will learn how to apply functions to sequences using different function attributes and implement recursion. For accessing collections of data, the chapter explains how to use iterators, generators, and generator expressions. You will learn to import and use modules for built-in functions. The chapter also explains how to pass command-line arguments to a Python program.
Chapter 5, “Classes”: This chapter focuses on classes. You will learn how to define a class, define functions for it, initialize its instance variables, and use class and static methods. You will also learn to use class attributes to display specific information related to the class. You will learn the concept of garbage collection and its role in freeing up memory consumed by objects that are out of scope. Also, you will learn to apply single, multilevel, and multiple inheritance through running practical examples. You will learn the use of private and public access specifiers and how to apply method overriding and operator overloading to perform arithmetic operations on instances. Finally, the chapter explains polymorphism and setting and getting values of instance attributes through properties and descriptors.
Chapter 6, “File Handling”: In this chapter, you will learn to perform different operations on files. You will learn to open a file in different modes and to read its contents, update existing content, delete content, and append new content. You will also see how to copy a file, read a file sequentially or randomly, and read only specific content. You will learn to create a binary file as well as pickle and unpickle objects. Finally, the chapter explains how to implement exception handling and the procedure for raising exceptions.
Chapter 7, “PyQt”: In this chapter, you will be introduced to the Qt toolkit, Qt Designer, and PyQt. You will learn about different Qt Designer components, such as the toolbar, the Object Inspector, the Property Editor, and the Widget Box. You will also learn to create a GUI application through coding. Also, you will learn about the fundamental Label, Line Edit, and Push Button widgets as well as learn to develop applications using them. You will also learn about signal/slot connection in the Qt Designer and how to connect signals to both predefined slots and to custom slots.
Chapter 8, “Basic Widgets”: This chapter demonstrates how to create a GUI application using Radio Buttons, which enable the user to select one option out of several. You will also learn how to select more than one option by using CheckBoxes and specify integers as well as float values using Spin Boxes. Also, you will learn to use ScrollBars and Sliders to display large documents and represent integer values. Finally, the chapter explains how to display options with a List widget, add items to a List widget, and delete and edit existing items in a List widget.
Chapter 9, “Advanced Widgets”: This chapter explains how to access and display system clock time in LCD digits. You also will see how to display a calendar and display a selected date in different formats. You will learn to create an application that displays options with a Combo Box, displays information with a Table widget, displays web pages, and displays graphics.
Chapter 10, “Menus and Toolbars”: In this chapter, you will learn to create menus and toolbars. Also, you will learn about the Action Editor and how it can help you define actions for menus and toolbars. You will also learn how to manage application resources in one place through a resource file. You will see how to create dockable windows and how to display information in small chunks with the Tab widget. Finally, the chapter explains how to convert a Tab widget into a Tool Box or Stacked widget.
Chapter 11, “Multiple Documents and Layouts”: In this chapter, you will learn to manage multiple documents in a main window through an MDI. You will see how child windows in MdiArea can be arranged in cascading and tile fashions. You will also learn to place a collection of widgets that do similar tasks in a Group Box. You will also learn to organize widgets in different layouts.
Chapter 12, “Database Handling”: In this chapter, you will learn to install and use the MySQLdb module, which is required in order to access the MySQL Database Server through Python. Also, you will learn to maintain a database through console-based programs and through GUI programs. You will also learn to write Python scripts to insert, fetch, delete, search, and update rows in a database table.
You may download the companion website files from www.courseptr.com/downloads. Please note that you will be redirected to the Cengage Learning website.