在好例子网,分享、交流、成长!
您当前所在位置:首页Python 开发实例Python GUI开发 → Python GUI Programming Cookbook

Python GUI Programming Cookbook

Python GUI开发

下载此实例
  • 开发语言:Python
  • 实例大小:8.89M
  • 下载次数:12
  • 浏览次数:99
  • 发布时间:2023-02-10
  • 实例类别:Python GUI开发
  • 发 布 人:舒鹏
  • 文件格式:.pdf
  • 所需积分:4

实例介绍

【实例简介】Python GUI Programming Cookbook

【实例截图】

【核心代码】

Table of Contents
Preface 1
Chapter 1: Creating the GUI Form and Adding Widgets 7
Introduction 7
Creating our first Python GUI 9
Getting ready 9
How to do it… 10
How it works… 10
There's more… 11
Preventing the GUI from being resized 12
Getting ready 12
How to do it… 12
How it works… 13
Adding a label to the GUI form 14
Getting ready 14
How to do it… 14
How it works… 15
There's more… 16
Creating buttons and changing their text property 16
Getting ready 17
How to do it… 17
How it works… 18
There's more… 18
Text box widgets 19
Getting ready 19
How to do it… 19
How it works… 20
Setting the focus to a widget and disabling widgets 21
Getting ready 21
How to do it… 21
How it works… 23
There's more… 23
Combo box widgets 24
Getting ready 24
How to do it… 24
[ ii ]
How it works… 25
There's more… 26
Creating a check button with different initial states 26
Getting ready 26
How to do it… 27
How it works… 28
Using radio button widgets 28
Getting ready 29
How to do it… 29
How it works… 30
There's more… 31
Using scrolled text widgets 31
Getting ready 31
How to do it… 32
How it works… 33
Adding several widgets in a loop 34
Getting ready 34
How to do it… 34
How it works… 35
There's more… 35
Chapter 2: Layout Management 36
Introduction 36
Arranging several labels within a label frame widget 38
Getting ready 38
How to do it… 38
How it works… 40
There's more… 41
Using padding to add space around widgets 41
Getting ready 41
How to do it… 41
How it works… 42
How widgets dynamically expand the GUI 44
Getting ready 45
How to do it… 45
How it works… 49
There's more… 49
Aligning the GUI widgets by embedding frames within frames 49
Getting ready 49
How to do it… 50
书籍下载qq群6089740 钉钉群21734177 IT书籍 http://t.cn/RDIAj5D
电子书寻找看手相 钉钉或微信pythontesting
[ iii ]
How it works… 53
Creating menu bars 54
Getting ready 55
How to do it… 55
How it works… 61
There's more… 62
Creating tabbed widgets 62
Getting ready 62
How to do it… 63
How it works… 68
Using the grid layout manager 68
Getting ready… 68
How to do it… 68
How it works… 70
Chapter 3: Look and Feel Customization 71
Introduction 71
Creating message boxes – information, warning, and error 72
Getting ready 73
How to do it… 73
How it works… 75
How to create independent message boxes 77
Getting ready 77
How to do it… 77
How it works… 80
How to create the title of a tkinter window form 81
Getting ready 81
How to do it… 81
How it works… 81
Changing the icon of the main root window 82
Getting ready 82
How to do it… 82
How it works… 83
Using a spin box control 83
Getting ready 83
How to do it... 83
How it works… 87
Relief, sunken and raised appearance of widgets 87
Getting ready 87
How to do it… 88
[ iv ]
How it works… 89
Creating tooltips using Python 90
Getting ready 90
How to do it… 91
How it works… 93
Adding a progressbar to the GUI 94
Getting ready 94
How to do it… 95
How it works… 97
How to use the canvas widget 97
Getting ready 97
How to do it… 98
How it works… 98
Chapter 4: Data and Classes 100
Introduction 100
How to use StringVar() 102
Getting ready 102
How to do it… 103
How it works… 105
How to get data from a widget 108
Getting ready 108
How to do it… 108
How it works… 109
Using module-level global variables 110
Getting ready 110
How to do it… 110
How it works… 111
How coding in classes can improve the GUI 114
Getting ready 115
How to do it… 115
How it works… 120
Writing callback functions 120
Getting ready 121
How to do it… 121
How it works… 121
Creating reusable GUI components 122
Getting ready 122
How to do it… 122
How it works… 126
书籍下载qq群6089740 钉钉群21734177 IT书籍 http://t.cn/RDIAj5D
电子书寻找看手相 钉钉或微信pythontesting
[ v ]
Chapter 5: Matplotlib Charts 127
Introduction 127
Creating beautiful charts using Matplotlib 128
Getting ready 128
How to do it… 129
How it works… 131
Installing Matplotlib using pip with whl extension 131
Getting ready 131
How to do it… 134
How it works… 137
Creating our first chart 138
Getting ready 138
How to do it… 138
How it works… 139
Placing labels on charts 140
Getting ready 140
How to do it... 140
How it works… 145
How to give the chart a legend 146
Getting ready 146
How to do it… 146
How it works… 149
Scaling charts 149
Getting ready 150
How to do it… 150
How it works… 151
Adjusting the scale of charts dynamically 152
Getting ready 152
How to do it… 152
How it works… 156
Chapter 6: Threads and Networking 157
Introduction 157
How to create multiple threads 159
Getting ready 160
How to do it… 160
How it works… 163
Starting a thread 163
Getting ready 163
[ vi ]
How to do it… 165
How it works… 168
Stopping a thread 169
Getting ready 169
How to do it… 169
How it works… 172
How to use queues 173
Getting ready 173
How to do it… 174
How it works… 179
Passing queues among different modules 179
Getting ready 180
How to do it… 180
How it works… 182
Using dialog widgets to copy files to your network 183
Getting ready 183
How to do it… 183
How it works… 193
Using TCP/IP to communicate via networks 194
Getting ready 194
How to do it… 194
How it works… 197
Using urlopen to read data from websites 197
Getting ready 197
How to do it… 197
How it works… 201
Chapter 7: Storing Data in our MySQL Database via our GUI 202
Introduction 202
Installing and connecting to a MySQL server from Python 204
Getting ready 204
How to do it… 207
How it works… 210
Configuring the MySQL database connection 210
Getting ready 211
How to do it… 211
How it works… 214
Designing the Python GUI database 215
Getting ready 215
How to do it… 215
书籍下载qq群6089740 钉钉群21734177 IT书籍 http://t.cn/RDIAj5D
电子书寻找看手相 钉钉或微信pythontesting
[ vii ]
How it works… 222
Using the SQL INSERT command 222
Getting ready 223
How to do it… 223
How it works… 225
Using the SQL UPDATE command 225
Getting ready 226
How to do it… 226
How it works… 230
Using the SQL DELETE command 231
Getting ready 231
How to do it… 231
How it works… 235
Storing and retrieving data from our MySQL database 235
Getting ready 235
How to do it… 235
How it works… 239
Using the MySQL workbench 239
Getting ready 240
How to do it… 240
How it works… 246
There's more… 246
Chapter 8: Internationalization and Testing 247
Introduction 247
Displaying widget text in different languages 249
Getting ready 249
How to do it… 249
How it works… 251
Changing the entire GUI language, all at once 252
Getting ready 252
How to do it… 252
How it works… 257
Localizing the GUI 257
Getting ready 258
How to do it… 258
How it works… 262
Preparing the GUI for internationalization 263
Getting ready 263
How to do it… 263
[ viii ]
How it works… 267
How to design a GUI in an agile fashion 267
Getting ready 268
How to do it… 268
How it works… 271
Do we need to test the GUI code? 271
Getting ready 272
How to do it… 272
How it works… 275
Setting debug watches 275
Getting ready 276
How to do it… 276
How it works… 280
Configuring different debug output levels 280
Getting ready 280
How to do it… 281
How it works… 283
Creating self-testing code using Python's __main__ section 284
Getting ready 284
How to do it… 284
How it works… 289
Creating robust GUIs using unit tests 289
Getting ready 289
How to do it… 289
How it works… 293
How to write unit tests using the Eclipse PyDev IDE 293
Getting ready 294
How to do it… 294
How it works… 300
Chapter 9: Extending Our GUI with the wxPython Library 301
Introduction 301
Installing the wxPython library 303
Getting ready 303
How to do it… 303
How it works… 306
Creating our GUI in wxPython 306
Getting ready 307
How to do it… 307
How it works… 311
书籍下载qq群6089740 钉钉群21734177 IT书籍 http://t.cn/RDIAj5D
电子书寻找看手相 钉钉或微信pythontesting
[ ix ]
Quickly adding controls using wxPython 312
Getting ready 312
How to do it… 312
How it works… 317
Trying to embed a main wxPython app in a main tkinter app 318
Getting ready 318
How to do it… 319
How it works… 320
Trying to embed our tkinter GUI code into wxPython 321
Getting ready 321
How to do it… 321
How it works… 323
Using Python to control two different GUI frameworks 324
Getting ready 324
How to do it… 324
How it works… 326
Communicating between the two connected GUIs 327
Getting ready 328
How to do it… 328
How it works… 332
Chapter 10: Creating Amazing 3D GUIs with PyOpenGL and PyGLet 333
Introduction 333
PyOpenGL transforms our GUI 335
Getting ready 335
How to do it… 336
How it works… 339
Our GUI in 3D! 339
Getting ready 340
How to do it… 340
How it works… 344
Using bitmaps to make our GUI pretty 345
Getting ready 345
How to do it… 346
How it works… 348
PyGLet transforms our GUI easier than PyOpenGL 348
How to do it… 349
How it works… 351
Our GUI in amazing colors 351
Getting ready 352
[ x ]
How to do it… 352
How it works… 355
OpenGL animation 355
Getting ready 356
How to do it… 356
How it works… 362
Creating a slide show using tkinter 362
Getting ready 363
How to do it… 363
How it works… 368
Chapter 11: Best Practices 369
Introduction 369
Avoiding spaghetti code 370
Getting ready 371
How to do it… 371
How it works… 374
Using __init__ to connect modules 377
Getting ready 378
How to do it… 378
How it works… 383
Mixing fall-down and OOP coding 384
Getting ready 384
How to do it… 384
How it works… 388
Using a code naming convention 388
Getting ready 389
How to do it… 389
How it works… 391
When not to use OOP 392
Getting ready 392
How to do it… 392
How it works… 396
How to use design patterns successfully 396
Getting ready 396
How to do it… 396
How it works… 399
Avoiding complexity 399
Getting ready 399
How to do it… 400
书籍下载qq群6089740 钉钉群21734177 IT书籍 http://t.cn/RDIAj5D
电子书寻找看手相 钉钉或微信pythontesting
[ xi ]
How it works… 404
GUI design using multiple notebooks 405
Getting ready 405
How to do it… 405
How it works… 409
Index 413

实例下载地址

Python GUI Programming Cookbook

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警