没有合适的资源?快使用搜索试试~ 我知道了~
首页Python GUI编程秘籍:80个面向对象实例打造惊艳界面
"《Python GUI编程Cookbook》是一本面向经验丰富的Python程序员的实用指南,特别适合那些希望利用免费的Python GUI框架创建美观、高效和响应式的图形用户界面(GUI)的专业人士。作者Burkhard A. Meier采用任务驱动的方法,通过80多个面向对象的编程配方,帮助读者用最少的代码实现惊人的GUI设计。 本书首先引导读者使用Python内置的Tkinter模块创建GUI,逐步介绍如何运用布局管理器定制界面,使组件排列更灵活。随后,读者将学习如何转向面向对象编程(OOP),将OOP概念融入到Python GUI开发中,以便构建大型项目。书中的内容还将涵盖使用Matplotlib模块创建动态图表,以及在多线程环境下使用网络环境让GUI保持响应性。 在后续章节中,读者将学习如何将GUI与数据库相连,理解和实践单元测试,以及如何遵循最佳实践扩展GUI应用,探索其他Python GUI框架。此外,书中还涉及了国际化GUI的设计,确保应用程序在全球范围内都能顺畅运行。 整个过程中,读者将通过一步步的实战项目,不断积累知识和技能,最终成为Python GUI编程的专家,能够开发出各种常见的GUI应用程序。《Python GUI编程Cookbook》不仅注重实用性,还强调了清晰简洁的编程风格和逐步进阶的学习路径,适合寻求提升GUI设计能力的开发者使用。"
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/10828725/bg10.jpg)
Preface
ix
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen.
If you nd a mistake in one of our books—maybe a mistake in the text or the code—we would be
grateful if you could report this to us. By doing so, you can save other readers from frustration
and help us improve subsequent versions of this book. If you nd any errata, please report them
by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on
the Errata Submission Form link, and entering the details of your errata. Once your errata are
veried, your submission will be accepted and the errata will be uploaded to our website or
added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/
content/support
and enter the name of the book in the search eld. The required
information will appear under the Errata section.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At
Packt, we take the protection of our copyright and licenses very seriously. If you come across
any illegal copies of our works in any form on the Internet, please provide us with the location
address or website name immediately so that we can pursue a remedy.
Please contact us at copyright@packtpub.com with a link to the suspected
pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at questions@
packtpub.com
, and we will do our best to address the problem.
![](https://csdnimg.cn/release/download_crawler_static/10828725/bg11.jpg)
![](https://csdnimg.cn/release/download_crawler_static/10828725/bg12.jpg)
1
1
Creating the GUI Form
and Adding Widgets
In this chapter, we start creating amazing GUIs using Python 3:
f Creating our rst Python GUI
f Preventing the GUI from being resized
f Adding a label to the GUI form
f Creating buttons and changing their text property
f Text box widgets
f Setting the focus to a widget and disabling widgets
f Combo box widgets
f Creating a check button with different initial states
f Using radio button widgets
f Using scrolled text widgets
f Adding several widgets in a loop
Introduction
In this chapter, we will develop our rst GUI in Python. We start with the minimum code
required to build a running GUI application. Each recipe then adds different widgets to
the GUI form.
In the rst two recipes, we show the entire code, consisting of only a few lines of code. In the
following recipes we only show the code to be added to the previous recipes.
![](https://csdnimg.cn/release/download_crawler_static/10828725/bg13.jpg)
Creating the GUI Form and Adding Widgets
2
By the end of this chapter, we will have created a working GUI application that consists of
labels, buttons, text boxes, combo boxes, and check buttons in various states, as well as radio
buttons that change the background color of the GUI.
Creating our rst Python GUI
Python is a very powerful programming language. It ships with the built-in tkinter module.
In only a few lines of code (four, to be precise) we can build our rst Python GUI.
Getting ready
To follow this recipe, a working Python development environment is a prerequisite. The IDLE
GUI that ships with Python is enough to start. IDLE was built using tkinter!
All the recipes in this book were developed using Python 3.4 on a Windows 7
64-bit OS. They have not been tested on any other conguration. As Python
is a cross-platform language, the code from each recipe is expected to run
everywhere.
If you are using a Mac, it does come built-in with Python, yet it might be missing
some modules such as tkinter, which we will use throughout this book.
We are using Python 3 and the creator of Python intentionally chose not to
make it backwards compatible with Python 2.
If you are using a Mac or Python 2, you might have to install Python 3 from
www.python.org in order to successfully run the recipes in this book.
How to do it...
Here are the four lines of Python code required to create the resulting GUI:
import tkinter as tk # 1
win = tk.Tk() # 2
win.title("Python GUI") # 3
win.mainloop() # 4
![](https://csdnimg.cn/release/download_crawler_static/10828725/bg14.jpg)
Chapter 1
3
Execute this code and admire the result:
How it works...
In line 1, we import the built-in tkinter module and alias it as tk to simplify our Python code.
In line 2, we create an instance of the Tk class by calling its constructor (the parentheses
appended to Tk turn the class into an instance). We are using the alias tk so we don't have to
use the longer word tkinter. We are assigning the class instance to a variable named win
(short for a window). As Python is a dynamically typed language, we did not have to declare
this variable before assigning to it and we did not have to give it a specic type. Python infers
the type from the assignment of this statement. Python is a strongly typed language, so every
variable always has a type. We just don't have to specify its type beforehand like in other
languages. This makes Python a very powerful and productive language to program in.
A little note about classes and types:
In Python every variable always has a type. We cannot create a variable
without assigning it a type. Yet, in Python, we do not have to declare the
type beforehand, as we have to do in the C programming language.
Python is smart enough to infer the type. At the time of writing, C# also
has this capability.
Using Python, we can create our own classes using the class keyword
instead of the def keyword.
In order to assign the class to a variable, we rst have to create an
instance of our class. We create the instance and assign this instance
to our variable.
class AClass(object):
print('Hello from AClass')
classInstance = AClass()
Now the variable classInstance is of the type AClass.
If this sounds confusing, do not worry. We will cover OOP in the
coming chapters.
www.allitebooks.com
剩余350页未读,继续阅读
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/default.jpg!1)
C505512957
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- Vue实现iOS原生Picker组件:详细解析与实现思路
- Arduino蓝牙小车:参数调试与功能控制
- 百度Java面试精华:200页精选资源涵盖核心知识点
- Swift使用CoreData填坑指南:CoreData在Swift 3.0的变化
- 微距离无线充电器创新设计及其实验探索
- MTK Android平台开发全攻略:44步详解流程
- RecyclerView全面解析:替代ListView的新选择
- Android开发:自动适配中英文键盘解决方案
- Android调用WebService接口教程
- Android开发:BitmapUtil图片处理全解析与实例
- Android多线程断点续传实现详解
- PCA算法在人脸识别会议签到系统中的应用
- EventBus 3.0:Android事件总线详解与实战应用
- Android FileUtil:全面解析文件操作实用技巧与实例
- RecyclerView添加头部和尾部实战教程
- Android实现微博滑动固定顶部栏实战与优化
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)