2 回答

TA貢獻1898條經驗 獲得超8個贊
Tkinter 小部件是類。
但是在上面的文本例子中,某網站提到A text widget is created by using the Text() method.
那個網站不正確。它們是類,您可以通過查看 tkinter 的源代碼來驗證這一點,您會在其中看到每個小部件(Text
、Label
、Frame
等)的類定義。
例如,文本小部件的第一部分如下所示(取自 tkinter 的__init__.py文件):
class Text(Widget, XView, YView):
"""Text widget which can display text in various forms."""
def __init__(self, master=None, cnf={}, **kw):
"""Construct a text widget with the parent MASTER.
STANDARD OPTIONS
background, borderwidth, cursor,
exportselection, font, foreground,
highlightbackground, highlightcolor,
highlightthickness, insertbackground,
insertborderwidth, insertofftime,
insertontime, insertwidth, padx, pady,
relief, selectbackground,
selectborderwidth, selectforeground,
setgrid, takefocus,
xscrollcommand, yscrollcommand,
WIDGET-SPECIFIC OPTIONS
autoseparators, height, maxundo,
spacing1, spacing2, spacing3,
state, tabs, undo, width, wrap,
"""
Widget.__init__(self, master, 'text', cnf, kw)
添加回答
舉報