tkinter.ttk 资料整理+笔记(大全)

本文详细介绍了Python的tkinter.ttk模块,包括系统常量、模块信息,如name、doc、package等,以及重要的类如Style、Widget、Button等的属性和方法,展示了tkinter.ttk在GUI开发中的应用。
摘要由CSDN通过智能技术生成

tkinter.ttk 资料整理+笔记(大全)

以下来自于:printObj(tkinter.dict), 大侠Ahcao
英文为机器自动翻译(有道)+ 人工校对。
tkinter.ttk

tkinter.ttk

printObj(ttk.dict)
英文为机器自动翻译(有道)。

一、系统常量、模块

1 str name tkinter.ttk

2 str doc

Ttk包装。
这个模块提供了允许使用Tk主题小部件集的类。
Ttk基于tip#48 (http://tip.tcl.tk/48)指定样式引擎的修订和增强版本。
它的基本思想是尽可能地将实现小部件行为的代码与实现小部件外观的代码分开。
小部件类绑定主要负责维护小部件状态和调用回调,小部件外观的所有方面都位于主题。

3 str package tkinter

4 SourceFileLoader loader

<_frozen_importlib_external.SourceFileLoader object at 0x0000000002672608>

5 ModuleSpec spec

ModuleSpec(name=‘tkinter.ttk’, loader=<_frozen_importlib_external.SourceFileLoader object at 0x0000000002672608>, origin=‘……\lib\tkinter\ttk.py’)

6 str __file__ ……\lib\tkinter\ttk.py

7 str __cached__

……\lib\tkinter_pycache_\ttk.cpython-37.pyc

8 dict builtins {}

9 str version 0.3.1

10 str

author Guilherme Polo ggpolo@gmail.com

11 lst __all__

[‘Button’, ‘Checkbutton’, ‘Combobox’, ‘Entry’, ‘Frame’, ‘Label’, ‘Labelframe’, ‘LabelFrame’, ‘Menubutton’, ‘Notebook’, ‘Panedwindow’, ‘PanedWindow’, ‘Progressbar’, ‘Radiobutton’, ‘Scale’, ‘Scrollbar’, ‘Separator’, ‘Sizegrip’, ‘Spinbox’, ‘Style’, ‘Treeview’, ‘LabeledScale’, ‘OptionMenu’, ‘tclobjs_to_py’, ‘setup_master’]

12 module tkinter

<module ‘tkinter’ from ‘……\lib\tkinter_init_.py’>

二、类

13 type Style <class ‘tkinter.ttk.Style’>

1 str module tkinter.ttk

2 str doc

    操作样式数据库。

3 function init

<code object init at 0x0000000002692D20, file “……\lib\tkinter\ttk.py”, line 367>

4 getset_descriptor dict

<attribute ‘dict’ of ‘Style’ objects>

5 getset_descriptor weakref

<attribute ‘weakref’ of ‘Style’ objects>

○6 function configure

<code object configure at 0x0000000002692DB0, file “……\lib\tkinter\ttk.py”, line 378>
def configure(self, style, query_opt=None, **kw):
以样式查询或设置指定选项的默认值。
kw中的每个键都是一个选项,每个值都是一个字符串或一个序列,用于标识该选项的值。

○7 function map

<code object map at 0x0000000002692E40, file “……\lib\tkinter\ttk.py”, line 391>
def map(self, style, query_opt=None, **kw):
按样式查询或设置指定选项的动态值。
kw中的每个键都是一个选项,每个值都应该是一个列表或元组(通常),其中包含分组在元组、列表或其他您喜欢的东西中的状态。
一个statespec是一个或多个状态和一个值的复合。

○8 function lookup

<code object lookup at 0x0000000002692ED0, file “……\lib\tkinter\ttk.py”, line 409>
def lookup(self, style, option, state=None, default=None):
返回样式中为option指定的值。
如果指定了state,则期望它是一个或多个状态的序列。如果设置了default参数,则在没有找到option的说明时将其用作回退值。

○9 function layout

<code object layout at 0x0000000002692F60, file “……\lib\tkinter\ttk.py”, line 421>
def layout(self, style, layoutspec=None):
定义给定样式的小部件布局。
如果省略了layoutspec,则返回给定样式的布局规范。layoutspec应该是一个与None不同的列表或对象,如果你想“关闭”该样式,则该对象的值为False。
如果它是一个列表(或元组或其他东西),每个元素都应该是一个元组,其中第一项是布局名称,第二项应该具有如下所述的格式:

            LAYOUTS
            布局机制使用包几何管理器的简化版本:给定一个初始空腔,每个元素分配一个包。有效的选项/值是:
                side: whichside
                    指定放置元素的空腔的哪一边;上、右、下或左之一。如果省略,该元件将占据整个腔体。
                sticky: nswe
                    指定元素在分配的包中的位置。
                children: [sublayout... ]
                    指定要放置在元素中的元素列表。每个元素都是一个元组(或其他序列),其中第一项是布局名称,另一项是布局LAYOUT。

○10 function element_create

<code object element_create at 0x0000000002693030, file “……\lib\tkinter\ttk.py”, line 464>
def element_create(self, elementname, etype, *args, **kw):
在给定etype的当前主题中创建一个新元素。

○11 function element_names

<code object element_names at 0x0000000002693150, file “……\lib\tkinter\ttk.py”, line 471>
def element_names(self):
返回当前主题中定义的元素列表。

○12 function element_options

<code object element_options at 0x0000000002693270, file “……\lib\tkinter\ttk.py”, line 477>
def element_options(self, elementname):
返回elementname的选项列表。

○13 function theme_create

<code object theme_create at 0x0000000002693300, file “……\lib\tkinter\ttk.py”, line 483>
def theme_create(self, themename, parent=None, settings=None):
创建一个新主题。
如果该名称已经存在,则会出错。
如果指定了parent,新主题将从指定的父主题继承样式、元素和布局。
如果存在设置,则期望它们具有与主题设置相同的语法。

○14 function theme_settings

<code object theme_settings at 0x0000000002693390, file “……\lib\tkinter\ttk.py”, line 500>
def theme_settings(self, themename, settings):
临时设置当前主题为themename,应用指定的设置,然后恢复以前的主题。
设置中的每个键都是一种样式,每个值都可能包含键’configure’, ‘map’, ‘layout’和’element create’,
它们应该具有与分别由方法configure, map, layout和element_create指定的相同的格式。

○15 function theme_names

<code object theme_names at 0x0000000002693420, file “……\lib\tkinter\ttk.py”, line 512>
def theme_names(self):
返回所有已知主题的列表。

○16 function theme_use

<code object theme_use at 0x00000000026934B0, file “……\lib\tkinter\ttk.py”, line 517>
def theme_use(self, themename=None):
如果themename为None,则返回正在使用的主题,否则,将当前主题设置为themename,刷新所有小部件并发出 <> 事件。

Widget

14 type Widget <class ‘tkinter.ttk.Widget’>

1 str module tkinter.ttk

2 str doc

Tk主题小部件的基类。

3 function init

<code object init at 0x00000000026935D0, file “……\lib\tkinter\ttk.py”, line 535>
用父主组件构造一个Ttk小部件。

            标准选项类
                class, cursor, takefocus, style
            可滚动小部件选项
                xscrollcommand, yscrollcommand
            LABEL小部件选项
                text, textvariable, underline, image, compound, width
            小部件状态
                active, disabled, focus, pressed, selected, background,
                readonly, alternate, invalid

○4 function identify

<code object identify at 0x0000000002693660, file “……\lib\tkinter\ttk.py”, line 562>
def identify(self, x, y):
返回位于x、y位置的元素名称,如果该点不在任何元素中,则返回空字符串。X和y是相对于小部件的像素坐标。

○5 function instate

<code object instate at 0x00000000026936F0, file “……\lib\tkinter\ttk.py”, line 570>
def instate(self, statespec, callback=None, args, **kw):
测试小部件的状态。
如果callback未指定,如果小部件状态与statespec匹配则返回True,否则返回False。
如果指定了callback,那么如果小部件状态匹配statespec,它将被
args, **kw调用。预计Statespec将是一个序列。

○6 function state

<code object state at 0x0000000002693780, file “……\lib\tkinter\ttk.py”, line 585>
def state(self, statespec=None):
修改或查询小部件状态。
如果statespec为None,则返回窗口小部件状态,否则根据statespec标志设置窗口小部件状态,
然后返回一个新的状态规范,指示哪些标志被更改。预计Statespec将是一个序列。

Button

15 type Button <class ‘tkinter.ttk.Button’>

1 str module tkinter.ttk

2 str doc

Ttk按钮小部件,显示文本标签和/或图像,并在按下时执行命令。

3 function init

<code object init at 0x00000000026938A0, file “……\lib\tkinter\ttk.py”, line 602>
用父主组件构造一个Ttk Button小部件。

            标准选项:
                class, compound, cursor, image, state, style, takefocus, text, textvariable, underline, width
            WIDGET-特有项:
                command, default, width

○4 function invoke

<code object invoke at 0x0000000002693930, file “……\lib\tkinter\ttk.py”, line 617>
def invoke(self):
调用与按钮关联的命令。

Checkbutton

16 type Checkbutton <class ‘tkinter.ttk.Checkbutton’>

1 str module tkinter.ttk

2 str doc

Ttk检查按钮小部件,要么在打开或关闭状态。

3 function init

<code object init at 0x0000000002693A50, file “……\lib\tkinter\ttk.py”, line 625>
用父主组件构造一个Ttk Checkbutton小部件。
Construct a Ttk Checkbutton widget with the parent master.

    标准选项类,复合,游标,图像,状态,样式,取焦,文本,文本变量,下划线,宽度小部件特定选项:命令,offvalue, onvalue,变量
            标准选项:
                class, compound, cursor, image, state, style, takefocus, text, textvariable, underline, width
            小部件特定选项:
                command, offvalue, onvalue, variable

○4 function invoke

<code object invoke at 0x0000000002693AE0, file “……\lib\tkinter\ttk.py”, line 640>
def invoke(self):
在选定和取消选定的状态之间切换,并调用相关的命令。
如果小部件当前被选中,则将选项变量设置为offvalue选项并取消选择小部件;否则,将选项变量设置为 onvalue选项。返回相关命令的结果。

Entry

17 type Entry <class ‘tkinter.ttk.Entry’>

1 str module tkinter.ttk

2 str doc

    Entry小部件显示一行文本字符串,并允许用户编辑该字符串。

3 function init

<code object init at 0x0000000002693C90, file “……\lib\tkinter\ttk.py”, line 655>
构造带有父主组件的Ttk Entry小部件。

            标准选项:
                class, cursor, style, takefocus, xscrollcommand
            小部件特定选项:
                exportselection, invalidcommand, justify, show, state, textvariable, validate, validatecommand, width
            验证模式:
                none, key, focus, focusin, focusout, all

○4 function bbox

<code object bbox at 0x0000000002693D20, file “……\lib\tkinter\ttk.py”, line 674>
def bbox(self, index):
返回一个(x, y, width, height)的元组,用于描述index给出的字符的边界框。

○5 function identify

<code object identify at 0x0000000002693DB0, file “……\lib\tkinter\ttk.py”, line 680>
def identify(self, x, y):
返回位于x、y位置的元素名称,如果坐标在窗口外,则返回空字符串。</

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AhcaoZhu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值