Skip to Content
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
For Enterprise
For Government
For Higher Ed
For Individuals
For Marketing
Explore Skills
Cloud Computing
Microsoft Azure
Amazon Web Services (AWS)
Google Cloud
Cloud Migration
Cloud Deployment
Cloud Platforms
Data Engineering
Data Warehouse
SQL
Apache Spark
Microsoft SQL Server
MySQL
Kafka
Data Lake
Streaming & Messaging
NoSQL Databases
Relational Databases
Data Science
Pandas
R
MATLAB
SAS
D3
Power BI
Tableau
Statistics
Exploratory Data Analysis
Data Visualization
AI & ML
Generative AI
Machine Learning
Artificial Intelligence (AI)
Deep Learning
Reinforcement Learning
Natural Language Processing
TensorFlow
Scikit-Learn
Hyperparameter Tuning
MLOps
Programming Languages
Java
JavaScript
Spring
Python
Go
C#
C++
C
Swift
Rust
Functional Programming
Software Architecture
Object-Oriented
Distributed Systems
Domain-Driven Design
Architectural Patterns
IT/Ops
Kubernetes
Docker
GitHub
Terraform
Continuous Delivery
Continuous Integration
Database Administration
Computer Networking
Operating Systems
IT Certifications
Security
Network Security
Application Security
Incident Response
Zero Trust Model
Disaster Recovery
Penetration Testing / Ethical Hacking
Governance
Malware
Security Architecture
Security Engineering
Security Certifications
Design
Web Design
Graphic Design
Interaction Design
Film & Video
User Experience (UX)
Design Process
Design Tools
Business
Agile
Project Management
Product Management
Marketing
Human Resources
Finance
Team Management
Business Strategy
Digital Transformation
Organizational Leadership
Soft Skills
Professional Communication
Emotional Intelligence
Presentation Skills
Innovation
Critical Thinking
Public Speaking
Collaboration
Personal Productivity
Confidence / Motivation
Features
All features
Verifiable skills
AI Academy
Courses
Certifications
Interactive learning
Live events
Superstreams
Answers
Insights reporting
Radar Blog
Buy Courses
Plans
Sign In
Try Now
O'Reilly Platform
book
流畅的Python(第2版)
by
Luciano Ramalho
April 2023
Intermediate to advanced
769 pages
25h 16m
Chinese
Posts & Telecom Press
Content preview from
流畅的Python(第2版)
394
|
第
14
章
35
个改善编程与设计的有效方法(中文版)》一书中的一句话:“非尾端类都应设计为抽象
类。”也就是说,
Meyer
建议只有抽象类可以子类化。
如果子类化是为了重用代码,那么想要重用的代码应该放入抽象基类的混入方法中,或者
放入名称可明确表明意图的混入类中。
接下来,从这些建议入手分析
Tkinter
。
14.7.8
Tkinter
的好
、
不好以及令人厌恶的方面
前几节给出的建议,
Tkinter
大都没有采用,
14.7.5
节例外。但是,
Tkinter
做得并不好,因
为使用组合模式把几何管理器集成到
Widget
中或许更好,详见
14.7.1
节。
记住一点,自
1994
年发布的
Python 1.1
起,
Tkinter
就在标准库中了
。
Tkinter
的底层是
Tcl
语言优秀的
GUI
工具包
Tk
。
T
cl/Tk
组合原本不是面向对象的,因此
Tk API
基本上就是一
堆函数。尽管没有使用面向对象方式实现,但是这个工具包的理念极具面向对象思想。
tkinter.Widget
类的文档字符串开头说它是“内部类”。这或许表明,
Widget
应该被定义
为抽象基类。虽然
Widget
自身没有方法,但是它定义了接口。它传达的意思是:“每个
Tkinter
小组件都会提供基本的方法
(
__init__
、
destroy
,以及众多
Tk API
函数),此外
还会提供
3
个
几何管理器中的全部方法。”你可以不同意这是定义接口的好方式(太宽泛
了),但是这样确实能定义接口,
Widget
就把接口“定义”为超类接口的联合。
封装
GUI
应用程序逻辑的
Tk
类继承自
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial
You might also like
Python高级编程(第2版)
Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
Python语言及其应用(第2版)
Bill Lubanovic
Kafka权威指南(第2版)
Gwen Shapira, Todd Palino, Rajini Sivaram, Krit Petty
Python贝叶斯分析(第2版)
Posts & Telecom Press, Osvaldo Martin
Publisher Resources
ISBN: 9787115612366