Python GUI Programming with PAGE: Unlock the power of PAGE and create stunning Python GUIs with ease (English Edition)
()
About this ebook
This comprehensive book is your guide from installing the PAGE designer to mastering the creation of complex GUI interfaces. It covers a wide range of topics, from building front-end interfaces for SQLite databases (and other databases) to utilizing the Canvas widget for drawing shapes and text. The book explores various aspects, including working with standard Tk widgets (such as buttons and entry), leveraging the capabilities of the ttk toolkit, and extending GUI functionality through third-party widget libraries and custom widgets. Each chapter presents real-world usable programs that challenge readers to enhance their skills and become more productive in your programming careers.
By the end of the book, you will possess the skills and knowledge to confidently develop your own GUI Python programs.
Related to Python GUI Programming with PAGE
Related ebooks
Modern Web Development with Deno: Develop Modern JavaScript and TypeScript Code with Svelte, React, and GraphQL (English Edition) Rating: 0 out of 5 stars0 ratingsPython GUI Programming Cookbook - Second Edition Rating: 5 out of 5 stars5/5Bootstrap By Example Rating: 0 out of 5 stars0 ratingsPython Apps on Visual Studio Code: Develop apps and utilize the true potential of Visual Studio Code (English Edition) Rating: 0 out of 5 stars0 ratingsMy First Website for Students: Build Your First Website from Design to Code with Ease (English Edition) Rating: 0 out of 5 stars0 ratings.NET 7 for Jobseekers: Elevate your coding journey with .NET 7 (English Edition) Rating: 0 out of 5 stars0 ratingsCreating Templates with Artisteer Rating: 0 out of 5 stars0 ratingsBuilding Server-side and Microservices with Go: Building Modern Backends and Microservices Using Go, Docker and Kubernetes Rating: 0 out of 5 stars0 ratingsPySide GUI Application Development - Second Edition Rating: 0 out of 5 stars0 ratingsAdvance Core Python Programming: Begin your Journey to Master the World of Python (English Edition) Rating: 4 out of 5 stars4/5Exploring Web Components: Build Reusable UI Web Components with Standard Technologies (English Edition) Rating: 0 out of 5 stars0 ratingsGetting Started with Gulp – Second Edition Rating: 0 out of 5 stars0 ratingsGetting Started with React Native Rating: 4 out of 5 stars4/5Reactive State for Angular with NgRx Rating: 0 out of 5 stars0 ratingsPython Internals for Developers: Practice Python 3.x Fundamentals, Including Data Structures, Asymptotic Analysis, and Data Types Rating: 0 out of 5 stars0 ratingsBasic Core Python Programming: A Complete Reference Book to Master Python with Practical Applications (English Edition) Rating: 0 out of 5 stars0 ratingsHands-On System Design: Learn System Design, Scaling Applications, Software Development Design Patterns with Real Use-Cases Rating: 0 out of 5 stars0 ratingsPython In - Depth: Use Python Programming Features, Techniques, and Modules to Solve Everyday Problems Rating: 0 out of 5 stars0 ratingsGetting Started with RethinkDB Rating: 0 out of 5 stars0 ratingsEnterprise Automation with Python: Automate Excel, Web, Documents, Emails, and Various Workloads with Easy-to-code Python Scripts Rating: 0 out of 5 stars0 ratingsBootstrap for ASP.NET MVC - Second Edition Rating: 5 out of 5 stars5/5Developing Windows Store Apps with HTML5 and JavaScript Rating: 0 out of 5 stars0 ratingsJava for Web Development: Create Full-Stack Java Applications with Servlets, JSP Pages, MVC Pattern and Database Connectivity Rating: 0 out of 5 stars0 ratings
Computers For You
Mastering ChatGPT: 21 Prompts Templates for Effortless Writing Rating: 5 out of 5 stars5/5Procreate for Beginners: Introduction to Procreate for Drawing and Illustrating on the iPad Rating: 0 out of 5 stars0 ratingsArtificial Intelligence: The Complete Beginner’s Guide to the Future of A.I. Rating: 4 out of 5 stars4/5Elon Musk Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Creating Online Courses with ChatGPT | A Step-by-Step Guide with Prompt Templates Rating: 4 out of 5 stars4/5Deep Search: How to Explore the Internet More Effectively Rating: 5 out of 5 stars5/5Fundamentals of Programming: Using Python Rating: 5 out of 5 stars5/5How to Create Cpn Numbers the Right way: A Step by Step Guide to Creating cpn Numbers Legally Rating: 4 out of 5 stars4/5People Skills for Analytical Thinkers Rating: 5 out of 5 stars5/5The ChatGPT Millionaire Handbook: Make Money Online With the Power of AI Technology Rating: 0 out of 5 stars0 ratingsPractical Lock Picking: A Physical Penetration Tester's Training Guide Rating: 5 out of 5 stars5/5ChatGPT Ultimate User Guide - How to Make Money Online Faster and More Precise Using AI Technology Rating: 0 out of 5 stars0 ratingsThe Mega Box: The Ultimate Guide to the Best Free Resources on the Internet Rating: 4 out of 5 stars4/5101 Awesome Builds: Minecraft® Secrets from the World's Greatest Crafters Rating: 4 out of 5 stars4/5CompTIA Security+ Practice Questions Rating: 2 out of 5 stars2/5Master Builder Roblox: The Essential Guide Rating: 4 out of 5 stars4/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5I Forced a Bot to Write This Book: A.I. Meets B.S. Rating: 4 out of 5 stars4/5Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are Rating: 4 out of 5 stars4/5The Professional Voiceover Handbook: Voiceover training, #1 Rating: 5 out of 5 stars5/5Dark Aeon: Transhumanism and the War Against Humanity Rating: 5 out of 5 stars5/5Remote/WebCam Notarization : Basic Understanding Rating: 3 out of 5 stars3/5Ultimate Guide to Mastering Command Blocks!: Minecraft Keys to Unlocking Secret Commands Rating: 5 out of 5 stars5/5CompTIA IT Fundamentals (ITF+) Study Guide: Exam FC0-U61 Rating: 0 out of 5 stars0 ratings
Reviews for Python GUI Programming with PAGE
0 ratings0 reviews
Book preview
Python GUI Programming with PAGE - Gregory Walters
Chapter 1
Introduction to PAGE
Introduction
It’s now time to start learning PAGE. This chapter will concentrate on the basics of using PAGE and creating your own GUI front ends for your programs. Remember, the whole point of PAGE is to allow you to rapidly design and modify graphical interfaces.
The process of creating your GUI is to place widgets, or controls, onto a blank designer form. With PAGE, we can place those widgets by simply clicking on the widget you desire in the Widget Toolbar and clicking on the designer form somewhere close to the position you want it to live. You can move widgets by simply dragging them around the form or using the keyboard arrow keys to fine-tune
their position.
What you will learn
Following are the topics that you will learn in this topic:
Starting PAGE within your Operating System
The major functions each window provides
Basic use of the Label widget
Basic use of the Button widget
Basic use of the Frame widget
Basic use of the Radiobutton widget
Creating a GUI form
Saving a PAGE project
As I said in the Introduction, one important step to a successful project is the way you start PAGE.
Starting page
This section will show the best ways to start PAGE for your operating system and a quick overview of all of the windows that make up the PAGE program.
If you haven’t already done so, create a folder to hold your source code and assets (images, databases, and so on.).
If you are running Linux, MacOS, or Raspberry Pi, use the GUI File Manager, navigate to your development folder, and use the right mouse button to get the context menu. Select "Open in Terminal. Once the terminal is open, assuming you set up your terminal resource file, type
page".
If you are running Windows, use File Explorer to navigate to your project folder. Once there, press {Ctrl}-L to edit the address bar and type "cmd. This will open a new command prompt and type
winpage.bat or
c:\page\winpage.bat".
No matter which operating system you are running, you should be presented with 5 different Windows arranged around your screen. It should look something like the one shown in Figure 1.1:
Figure 1.1: The Page Windows
The PAGE designer forms
With 5 different windows taking up the majority of your screen, it’s hard to know where to start the first time you run PAGE. Let’s take a moment to take a look at each window to see what it is for.
The Main Window
The main window as shown in Figure 1.2 is important for many reasons. It contains the commands to save your project and generate your Python code. There are many other options that you will occasionally use, but for the most part, you will use this window the least out of all the other windows as shown in Figure 1.2:
Figure 1.2: The Main Window
At the very top left of the window, you will find the menu. At the bottom left, you will find the status box, which shows things that PAGE wants you to know. Near the right-hand side, again on the bottom, is a button that will say either Absolute
or Relative
. You can click on it to change the placement mode. The Absolute mode will use an exact X/Y position for the placement of your widgets. In the Relative mode, a more general method for the placement is used. The big difference is that if you select the Relative mode when the designed form is resized, the widgets will resize along with the form and the positions of the widgets will move in relationship with the size. In the Absolute mode, the size and position of all the widgets remain the same, no matter how the user resizes the form.
When I design a GUI, 99% of the time I use the Absolute mode, yet Don, the author of PAGE uses the Relative mode all the time.
We’ll explore some of the other menu options as we go through the next few chapters.
The Attribute Editor
The Attribute Editor shown in Figure 1.3 is one of the windows that you will spend a great deal of time using. This is where you set the various attributes of each widget. It is divided into three sections: Widget general attributes and Attributes section is where you can set specific information for things like the text displayed on the widget or a command callback function. The final section is the Geometry section where you can set the width/height and the X/Y position as well as a few other things:
Figure 1.3: The Attribute Editor
This is one of the windows where you will spend a great deal of time using. This is where you set the various attributes of each widget. It is divided into three sections, Widget general attributes, Attributes where you set specific information for things like the text displayed on the widget or a command callback function. The final section is the Geometry section where you set the width/height and the X/Y position as well as a few other things.
If one or more of the sections don’t show the proper attributes, simply click on the gray bar for that section and it will expand out so that you can see all the attributes.
The Attributes section changes, depending on the specific widget you have selected. For example, some of the widgets don’t have a command callback option or attribute, so it will not show for those widgets.
We’ll discuss various widget attributes later in this chapter and in Chapter 4, Standard Widgets as well as the various projects as we go forward.
The Widget Tree
Continuing around the screen in a clockwise manner, we get to the widget tree as shown in Figure 1.4:
Figure 1.4: The Widget Tree
Every widget that you add to the form will show up here as well as on the main form itself. This provides a quick and easy way to select a widget without the risk of moving the widget, which can be a concern in very complex forms that have several widgets. We’ll look at this more throughout the other chapters.
The Widget toolbar
The Widget toolbar shown in Figure 1.5 will be one of the windows that you will spend a lot of time with. This scrollable window holds all the widgets that you can use to create your GUI form:
Figure 1.5 The Widget Toolbar
Think of it as an artist’s palette of colors. When you want to put a widget on your main form, simply click on the widget to select it (the status area of the main window will acknowledge your selection by changing to something like Insert Button
), then move the mouse button to the general location you wish to place it on the designer form and click on the form with your left mouse button. That’s it. You don’t even need to drag and drop it. Click once on the toolbar then click again on the designer form.
I will probably be referring to this window as the toolbox
from here onwards.
The Designer form
If the toolbox is the artist’s palette, the Designer form is the canvas. This is not to be confused with the canvas widget. It is officially called the TopLevel widget (Refer to Figure 1.6). The designer form is blank when you start PAGE:
Figure 1.6: The Designer Form
That confuses many people, but that’s what it is really called. It is actually a widget, just like a button or static text label. This holds all the other widgets that make up our GUI. At the top of the form is the title. You can modify this using the Attribute Editor or you can leave it with the default and change it in code at any time. We’ll see that later on. It also has an alias by default of Toplevel1
. Again, you can change this or leave it with the default.
The Layout of the windows
Since there are so many windows for PAGE and since they are pretty big, the default layout might not work for you. Any or all the windows can be moved and resized at will. To move a window, simply click on the title bar of the window and drag it to where you want. To resize a window, move your mouse cursor to the edge of the window and click and drag to whatever size you wish. Feel free to move things wherever you find to be the most productive layout. To have PAGE, remember the new layout, start a new project in PAGE, and arrange the windows to whatever position and size you want. Then, without adding any widgets, simply close PAGE. When you reopen it, the different windows should all be in the size and position that you left them in. You don’t have to manually save anything.
GUI design
Our first project will focus on the basics. We will create a form with multiple widgets on it, and learn how to control them from code.
Here is what our GUI should look like when we are finished:
Figure 1.7: Our first GUI form
I won’t tell you exactly where to put the widgets. All you need to do is place them somewhere on the main form, making your form look something like the one in Figure 1.7. Let’s get started.
The first thing to put on the form is the Exit button. Using the toolbox, select the button widget, which should be the top icon as shown in Figure 1.8.
Figure 1.8: Button icon in Toolbox
If you don’t see it, use the scroll bar on the right of the toolbox and scroll all the way to the top. Click on the Button icon and you should see the ‘Insert Button’ appear in the status box of the main PAGE window. It should go somewhere on the upper right-hand corner of the form. Move your mouse cursor to somewhere close to the right side of the designer form. To place the button, simply click on the mouse