没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Python Tkinter
by
Mark Roseman
1
Table of Contents
Python Tkinter......................................................................................................................................1
Introduction..........................................................................................................................................6
Who this Tutorial is for....................................................................................................................6
Modern Best Practices.....................................................................................................................6
Tk Extensions..............................................................................................................................7
The Better Way Forward..................................................................................................................7
How to Use......................................................................................................................................7
Conventions................................................................................................................................8
Installing Tk..........................................................................................................................................8
Installing Tk on Mac OS X..............................................................................................................9
Installing Tk on Windows................................................................................................................9
Installing Tk on Linux...................................................................................................................10
The Obligatory First Program........................................................................................................10
A First (Real) Example.......................................................................................................................11
Design............................................................................................................................................11
Code...............................................................................................................................................12
A Note on Coding Style............................................................................................................13
Step-by-Step Walkthrough.............................................................................................................13
What's Missing...............................................................................................................................15
Tk Concepts........................................................................................................................................15
Widgets..........................................................................................................................................16
Widget Classes..........................................................................................................................16
Window Hierarchy....................................................................................................................16
Creating and Using Widgets......................................................................................................16
Configuration Options...............................................................................................................17
Geometry Management..................................................................................................................18
The Problem..............................................................................................................................18
How it Works............................................................................................................................18
Event Handling..............................................................................................................................19
Command Callbacks.................................................................................................................19
Event Bindings..........................................................................................................................19
Virtual Events.......................................................................................................................20
Multiple Bindings.................................................................................................................20
Basic Widgets.....................................................................................................................................20
Frame.............................................................................................................................................21
Requested Size.....................................................................................................................21
Padding.................................................................................................................................21
Borders.................................................................................................................................22
Changing Styles....................................................................................................................22
Label..............................................................................................................................................22
Displaying Text....................................................................................................................23
Displaying Images................................................................................................................23
Layout...................................................................................................................................23
Fonts, Colors and More........................................................................................................24
Button.............................................................................................................................................24
2
Text or Image........................................................................................................................25
The Command Callback.......................................................................................................25
Button State..........................................................................................................................25
Checkbutton...................................................................................................................................26
Widget Value........................................................................................................................27
Radiobutton....................................................................................................................................27
Entry...............................................................................................................................................28
Passwords.............................................................................................................................28
Widget States........................................................................................................................28
Validation..............................................................................................................................28
Combobox......................................................................................................................................29
Predefined Values.................................................................................................................29
The Grid Geometry Manager.............................................................................................................30
Columns and Rows........................................................................................................................30
Spanning Multiple Cells................................................................................................................31
Layout within the Cell...................................................................................................................32
Handling Resize.............................................................................................................................32
Padding..........................................................................................................................................32
Additional Grid Features...............................................................................................................34
Querying and Changing Grid Options......................................................................................34
Internal Padding........................................................................................................................35
Forget and Remove...................................................................................................................35
Nested Layouts..........................................................................................................................35
More Widgets.....................................................................................................................................35
Listbox...........................................................................................................................................36
Populating the Listbox Items....................................................................................................36
Selecting Items..........................................................................................................................37
Stylizing the List.......................................................................................................................37
Keeping Extra Item Data...........................................................................................................37
Example....................................................................................................................................38
Scrollbar.........................................................................................................................................40
Example....................................................................................................................................41
SizeGrip.........................................................................................................................................41
Text................................................................................................................................................42
Contents....................................................................................................................................43
Progressbar.....................................................................................................................................43
Determinate Progess.................................................................................................................44
Indeterminate Progress..............................................................................................................44
Scale...............................................................................................................................................44
Spinbox..........................................................................................................................................45
Menus.................................................................................................................................................46
Menubars.......................................................................................................................................46
Menu Widgets and Hierarchy....................................................................................................47
Before you Start........................................................................................................................47
Creating a Menubar...................................................................................................................47
Adding Menus...........................................................................................................................48
Adding Menu Items..................................................................................................................48
Types of Menu Items.................................................................................................................48
Accelerator Keys.......................................................................................................................49
More on Item Options...............................................................................................................49
3
Underline..............................................................................................................................49
Images..................................................................................................................................49
State......................................................................................................................................49
Querying and Changing Item Options..................................................................................50
Platform Menus..............................................................................................................................50
Mac OS X..................................................................................................................................50
Windows....................................................................................................................................50
X11............................................................................................................................................50
Contextual Menus..........................................................................................................................51
Windows and Dialogs.........................................................................................................................51
Creating and Destroying Windows................................................................................................52
Changing Window Behavior and Styles........................................................................................52
Window Title........................................................................................................................52
Size and Location.................................................................................................................52
Stacking Order......................................................................................................................53
Resizing Behavior................................................................................................................53
Iconifying and Withdrawing.................................................................................................54
Standard Dialogs............................................................................................................................54
Selecting Files and Directories.............................................................................................54
Selecting Colors...................................................................................................................55
Alert and Confirmation Dialogs...........................................................................................56
Organizing Complex Interfaces..........................................................................................................57
Multiple windows.................................................................................................................57
White space..........................................................................................................................57
Separator........................................................................................................................................57
Label Frames..................................................................................................................................58
Paned Windows..............................................................................................................................59
Notebook........................................................................................................................................59
Fonts, Colors, Images.........................................................................................................................60
Fonts...............................................................................................................................................60
Standard Fonts...........................................................................................................................61
Platform-Specific Fonts............................................................................................................61
Named Fonts.............................................................................................................................61
Font Descriptions......................................................................................................................62
Colors.............................................................................................................................................62
Images............................................................................................................................................62
Canvas................................................................................................................................................63
Creating Items................................................................................................................................63
Item Attributes...............................................................................................................................64
Bindings.........................................................................................................................................65
Tags................................................................................................................................................65
Modifying Items............................................................................................................................67
Scrolling.........................................................................................................................................67
Other Item Types............................................................................................................................68
Text.....................................................................................................................................................69
The Basics......................................................................................................................................69
Providing Initial Content...........................................................................................................69
Scrolling....................................................................................................................................70
Controlling Wrapping................................................................................................................70
Disabling the Widget.................................................................................................................70
4
Retrieving the Text....................................................................................................................70
Modifying the Text in Code...........................................................................................................70
Text Positions and Indices.........................................................................................................70
Deleting Text.............................................................................................................................71
Example: Logging Window......................................................................................................71
Formatting with Tags.....................................................................................................................72
Adding Tags to Text..................................................................................................................72
Applying Formatting to Tags....................................................................................................72
More Tag Manipulations...........................................................................................................72
Differences between Tags in Canvas and Text Widgets............................................................73
Events and Bindings......................................................................................................................73
Selecting Text.................................................................................................................................73
Marks.............................................................................................................................................74
Images and Widgets.......................................................................................................................74
Even More......................................................................................................................................75
Search........................................................................................................................................75
Modifications, Undo and Redo.................................................................................................75
Eliding Text...............................................................................................................................75
Introspection..............................................................................................................................75
Peering......................................................................................................................................75
Tree.....................................................................................................................................................75
Adding Items to the Tree...............................................................................................................76
Rearranging Items..........................................................................................................................77
Displaying Information for each Item...........................................................................................77
Item Appearance and Events..........................................................................................................78
Customizing the Display................................................................................................................78
Styles and Themes..............................................................................................................................78
Definitions.....................................................................................................................................78
Widget Class.............................................................................................................................78
Widget State..............................................................................................................................79
Style..........................................................................................................................................79
Themes......................................................................................................................................80
Using Styles and Themes...............................................................................................................80
Style Names..............................................................................................................................80
Using a Style.............................................................................................................................80
Using Themes............................................................................................................................80
What's Inside a Style?....................................................................................................................81
Elements....................................................................................................................................81
Layout.......................................................................................................................................82
Element Options........................................................................................................................83
Changing Style Options.................................................................................................................83
Modifying a Style Option.........................................................................................................83
Creating a New, Derived Style..................................................................................................83
State Specific Style Options......................................................................................................84
Sound Difficult to you?..................................................................................................................84
Advanced: More on Elements........................................................................................................86
5
剩余86页未读,继续阅读
编程之路从0到1
- 粉丝: 1w+
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 微信自动抢红包APP.zip
- 微信抢红包神器-红包鸟(可以抢多种情况下的红包,支持手机息屏抢红包、屏蔽群抢红包).zip
- 微信抢红包,支持xposed与免root,xposed支持最新版,免root需自己实现.zip
- 一维卷积神经网络英语电影评论情感分类项目功能实现-Embedding层
- 微信 自动抢红包 插件外挂(Android),实现了监控通知栏,自动点击红包等功能,帮助大家快速抢到红包.zip
- 满满的干货:分享二十个Python学习资源材料.zip
- USD ISO14229-1-2013 中文版
- STM32单片机FPGA毕设电路原理论文报告模糊控制器在无线监控机群系统中的应用
- OpenWrt-Toolchain-ipq
- STM32单片机FPGA毕设电路原理论文报告模糊控制逆变弧焊电源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页