Skip to Content
流畅的Python(第2版)
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.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python高级编程(第2版)

Python高级编程(第2版)

Posts & Telecom Press, Michał Jaworski, Tarek Ziadé
Python贝叶斯分析(第2版)

Python贝叶斯分析(第2版)

Posts & Telecom Press, Osvaldo Martin
高效能PYTHON程式設計

高效能PYTHON程式設計

Micha Gorelick, Ian Ozsvald

Publisher Resources

ISBN: 9787115612366