最近涉及到须要实现一个桌面UI的小游戏,因此就翻看了一些文档。html
固然有介绍使用pyQT5的,可是本机安装的是python3.4,不想卸载掉这个版本,暂时还不能使用pyQT5.python
pyQT5须要python3.5及以上的版本才能行。git
因此就使用python自带的tkinter了。web
总的来讲,图形界面的使用基本都是相通的,只要学通一个,其余的也会很是方便的入门。数据库
祝各位可以找到本身所需,那么,我这篇文章也就还算有一些价值了。api
tkinter是Tk interface表明着图形工具接口,当前python3后安装自带的图形包。
Tcl(最先称为“工具命令语言”"Tool Command Language"),Tk 是 Tcl“图形工具箱”的扩展,它提供各类标准的 GUI 接口项,以利于迅速进行高级应用程序开发,ttk 是Tk themed 表明有专用主题的图形工具箱。app
本文档主要介绍了一些图形控件的参数使用,并无将全部的方法都一一列出,有须要进一步学习的,能够直接查看源码文件,也能够查看我在最后附上的连接。框架
使用方式
import tkinter
或者,一般会以以下的方式导入
from tkinter import *ide
介绍一些类:
Wm : Windows manager 窗口管理
Misc :内置方法定义内部部件经常使用方法的基类
Variable :变量,子类有 StringVar, IntVar, DoubleVar, BooleanVar
CallWrapper :
Tk :构件
Pack :位置填充
Place :位置设定
Grid :网格化位置
BaseWidget :基础构件
Widget(BaseWidget, Pack, Place, Grid)函数
tkinter.scrolledtext
Text widget with a vertical scroll bar built in.
内置垂直滚动条的文本小部件。
tkinter.colorchooser
Dialog to let the user choose a color.
让用户选择颜色的对话框。
tkinter.commondialog
Base class for the dialogs defined in the other modules listed here.
其余模块中定义的对话框的基类。
tkinter.filedialog
Common dialogs to allow the user to specify a file to open or save.
容许用户指定要打开或保存的文件的通用对话框。
tkinter.font
Utilities to help work with fonts.
帮助字体工做的实用工具。
tkinter.messagebox
Access to standard Tk dialog boxes.
访问标准TK对话框。
tkinter.simpledialog
Basic dialogs and convenience functions.
基本对话框和方便功能。
tkinter.dnd
Drag-and-drop support for tkinter. This is experimental and should become deprecated when it is replaced with the Tk DND.
Tkinter支持拖放。可是,这是实验性的。应该成为过期的,应当被TK DND取代。
turtle
Turtle graphics in a Tk window.
海龟图形在传统的窗口。 ???
Tk was written by John Ousterhout while at Berkeley.
Tkinter was written by Steen Lumholt and Guido van Rossum.
================================================================
import tkinter as tk class Application(tk.Frame): def __init__(self, master=None): super().__init__(master) self.pack() self.create_widgets() def create_widgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello World\n(click me)" self.hi_there["command"] = self.say_hi self.hi_there.pack(side="top") self.quit = tk.Button(self, text="QUIT", fg="red", command=root.destroy) self.quit.pack(side="bottom") def say_hi(self): print("hi there, everyone!") root = tk.Tk() app = Application(master=root) app.mainloop()
================================================================
ttk是加强版的tk,其中有17个图形类,包括tk中的11个类:
Button, Checkbutton, Entry, Frame, Label, LabelFrame, Menubutton, PanedWindow, Radiobutton, Scale, Scrollbar
ttk新增的6个: Combobox, Notebook, Progressbar, Separator, Sizegrip, Treeview
这17个类都继承自 Widget。
place 是设置控件的位置,以坐标的方式进行
place是最简单的几何形状的管理,在Tkinter提供的三个通用几何图形管理。
它容许显式地设置窗口的位置和大小,不管是绝对值,仍是相对于另外一个窗口。
一般不会使用place来管理窗口控件的位置,它只是为了让工做变得简单,正常工做。
通常推荐使用pack和grid方式来进行控件控制。
然而,place在特殊状况下有其用途。最重要的是,它能够由复合小部件容器实现各类自定义几何管理器。另外一个用途是在对话框中放置控制按钮,实现不一样控件的覆盖。
place(**options) [#]
Place this widget relative to its parent.
**options
Geometry options.
anchor= # 锚,停靠的地方,默认是:图形位置的西北
默认值是 NW.
bordermode= # 边框模式,默认是:内边界
默认值是 INSIDE.
height= # 高度
无默认值.
in= # 控制在某个控件内,in是python中的关键字,一般使用 in_ 代替
默认值是 ..
relheight= # 相对高度
无默认值.
relwidth= # 相对宽度
无默认值.
relx= # 相对水平距离
默认值是 0.
rely= # 相对垂直距离
默认值是 0.
width= # 宽度
无默认值.
x= # 相对于水平的距离,以像素为单位
默认值是 0.
y= # 相对于垂直的距离,以像素为单位
默认值是 0.
pack 是控件内的填充,通常会是填充整个控件
相比于grid管理,pack管理是有所限制的,但它更容易使用一些。
一、将一个小部件放入框架(或任何其余容器小部件)中,并填充整个框架。
二、将许多小部件放在彼此之上。
三、并排放置多个小部件。
若是你须要建立更复杂的布局,一般你须要使用额外的框架部件的部件组。你也可使用网格管理器代替。
注意:不要在同一主窗口中混合使用grid和pack。tkinter没法兼顾到两种
pack(**options) [#]
**options
anchor=
将小部件放在pack。默认位置为中心 CENTER ,其余的还有N,NE,E,SE,S,SW,W,NW,or CENTER.。
expand=
指定是否应扩展小部件以填充几何主机中的任何额外空间。若是为false(默认),则未扩展小部件。
fill=
指定小部件是否应该占用主提供给它的全部空间。若是NONE没有(默认),保留小部件的原始大小。若是x(水平填充),y(垂直填充),或者 BOTH 二者都,沿着这个方向填充给定的空间。
要使一个小部件填充整个主窗口小部件,将填充设置为两个,而后扩展到非零值。
in=
将此小部件打包到给定的小部件内。你只能装在它的父控件,或在任何后学其父。这个选项一般应该被忽略,在这种状况下,小部件被打包在其父进程内。
注意,在Python中是一个保留字。使用它做为一个关键词的选择,添加一个下划线(in_)。
ipadx=
水平内部填充。默认值是0。
ipady=
垂直内部填充。默认值是0。
padx=
水平扩展,外部填充。默认值是0。
pady=
垂直扩展,外部填充。默认值是0。
side=
指定包装小部件的哪一面。要垂直包装小部件,使用TOP(默认)。要横向包装小部件,请使用LEFT。
您还能够沿着(BOTTOM and RIGHT)右下角包装小部件。您能够在一个单一的几何管理器中混合边,但结果可能并不老是您指望的那样。虽然能够经过嵌套框架小部件来建立至关复杂的布局,但您可能更喜欢使用网格几何管理器来实现不平凡的布局。
grid 是以网格的方式进行设置控件位置
grid(**options) [#]
column=
在当前列插入一个小器件,列的其实数字是0,若是不设置,默认为0.
columnspan=
若是给定,则指示小部件单元应该跨越多个列。默认值是1。
in=
将小部件放入给定的部件中。你只能放置一个控件在其父控件上,或任何其父控件的子控件中。若是不提供此选项,则默认为父级。
注意,在Python中是一个保留字。使用它做为一个关键词的选择,添加一个下划线(in_)。
in_=
Same as in. See above.
ipadx=
可选水平内填充。就像padx,但填充里面的控件的边界。默认值是0。
ipady=
可选垂直内填充。就像pady,但填充里面的控件的边界。默认值是0。
padx=
可选的水平填充,以放置在单元格中的小部件周围。默认值是0。
pady=
可选的垂直填充,以放置在单元格中的小部件周围。默认值是0。
row=
在这行插入小部件。行号从0开始。若是省略,则默认为网格中的第一个空行。
rowspan=
若是给定,则指示小部件单元应该跨越多行。默认值是1。
sticky=
定义如何扩展小部件,若是生成的单元格大于小部件自己。这能够是常数S, N, E,和W ,也能够是任意组合NW、NE、SW和SE。
例如,W (west) 意味着小部件应该与左单元格边界对齐。W+E意味着小部件应该水平拉伸以填充整个单元。W+E+N+S意味着小部件应该在两个方向上展开,平铺在单元格内。默认是将小部件居中。
Frame: 框架部件
一个框架是屏幕上的矩形区域。该框架部件主要用于其余部件图形管控,或提供其余部件之间的填充。
config(**options) [#]
**options
background=
设置背景颜色。
bg=
Same as background.
borderwidth=
边框宽度。默认为0(没有边框)。
bd=
Same as borderwidth.
class=
默认值是 Frame. (class/Class)
colormap=
根据实际系统支持的颜色进行匹配。
container=
默认值是 0. (container/Container)
cursor=
鼠标指针放置在这个小部件上时要显示的光标。默认值是特定于系统的箭头光标。(光标/光标)
height=
默认值是 0. (height/Height)
highlightbackground=
高亮背景,限于特定系统。
highlightcolor=
高亮颜色,限于特定系统。
highlightthickness=
默认值是 0. 高亮厚度。
padx=
水平填充,默认是0
pady=
垂直填充,默认是0
relief=
边框装饰。默认是 FLAT 平的。其余值是 SUNKEN 凹陷、 RAISED 凸起、 GROOVE 凹槽和 RIDGE 脊。
注意显示的边界,你须要改变的边界宽度为0的默认值。
takefocus=
若是为真,用户可使用tab键移动到这个小部件。默认值是0。
visual= 视觉的,看得见的;
无默认值. (visual/Visual)
width= 宽度
默认值是 0. (width/Width)
Button:按钮
config(**options) [#]
**options
activebackground=
当标签被激活时使用的背景色(能够设置状态选项). 默认值为平台指定的. (选项的数据库名activeBackground, 类名是Foreground)
activeforeground=
标签激活时使用什么前景色。默认为平台指定的颜色. (activeForeground/Background)
anchor=
控制加载按钮的文本(或者图片)。使用N, NE, E, SE, S, SW, W, NW, or CENTER其中之一。默认值是CENTER. (anchor/Anchor)
background=
设置背景色,默认为系统指定(background/Background)
bg=
Same as background.
bitmap=
要在小部件中显示的位图。若是给定图像选项,则忽略此选项。 (bitmap/Bitmap)
borderwidth=
按钮边框的宽度。默认的是平台特定的,一般是1或2像素。 (borderWidth/BorderWidth)
bd=
Same as borderwidth.
command=
按下按钮时调用的函数或方法。回调函数能够是函数、绑定方法,或者任何其余可调用的Python对象。若是不使用此选项,则用户按下按钮时不会发生任何事情。 (command/Command)
compound=
控制如何将文本和图像组合在按钮中。默认状况下,若是给定一个图像或位图,则将其绘制为文本。若是将此选项设置为中心CENTER,则在图像顶部绘制文本。若是该选项设置为BOTTOM, LEFT, RIGHT, or TOP, 绘制的图像在文本旁 (使用BOTTOM绘制图像是会在文本下面etc.). 无默认值. (compound/Compound)
cursor=
鼠标移动到按钮上时显示的光标。(cursor/Cursor)
default=
若是设置,则按钮是默认按钮。它会显示这的绘图平台的具体指标(一般是一个额外的边界)。默认已禁用DISABLED (无默认行为)。(default/Default)
disabledforeground=
按钮禁用时使用的颜色。背景显示在背景色中。默认值是特定于系统的。(disabledForeground/DisabledForeground)
font=
按钮中使用的字体。按钮只能包含单个字体的文本。默认值是特定于系统的。 (font/Font)
foreground=
用于文本和位图内容的颜色。默认值是特定于系统的。(foreground/Foreground)
fg=
Same as foreground.
height=
按钮的高度。若是按钮显示文本,则以文本单位给出大小。若是按钮显示图像,则以像素(或屏幕单元)给出大小。若是省略了大小,则基于按钮内容计算。(height/Height)
highlightbackground=
当按钮没有焦点时,用于高亮边框的颜色。默认值是特定于系统的。 (highlightBackground/HighlightBackground)
highlightcolor=
当按钮具备焦点时,用于高亮边框的颜色。默认系统指定。 (highlightColor/HighlightColor)
highlightthickness=
突出边框的宽度。默认值是系统指定的(一般是1个或2个像素)。(highlightThickness/HighlightThickness)
image=
要在小部件中显示的图像。若是指定,则优先于文本和位图选项。(image/Image)
justify=
定义如何对齐多行文本。使用LEFT, RIGHT, CENTER. 默认是CENTER. (justify/Justify)
overrelief=
当鼠标移动到小部件上时可使用的其余救济。若是空,老是使用浮雕值。 (overRelief/OverRelief)
padx=
文本或图像和边框之间的额外水平填充。(padX/Pad)
pady=
文本或图像和边框之间的额外垂直填充。(padY/Pad)
relief=
边框装饰。一般当按下按钮是SUNKEN(凹陷的,下陷的), 不然是RAISED(凸出显示). 其余值有 GROOVE, RIDGE, FLAT(槽状的、脊状的或扁平的).默认值是RAISED. (relief/Relief)
repeatdelay= 重复延迟
(repeatDelay/RepeatDelay)
repeatinterval= 重复间隔
(repeatInterval/RepeatInterval)
state=
按钮状态: NORMAL, ACTIVE or DISABLED. 默认是 NORMAL. (state/State)
takefocus=
指示用户可使用tab键移动到该按钮。默认是一个空字符串,这意味着只有当它有任何键盘绑定时,按钮才会接受焦点。(换句话说默认是打开). (takeFocus/TakeFocus)
text=
要在按钮中显示的文本。文本能够包含换行。若是使用位图或图像选项,则忽略此选项 (除非使用复合选项). (text/Text)
textvariable=
按钮的Tkinter变量(一般是一个StringVar)。若是变量被更改,按钮文本将被更新。(textVariable/Variable)
underline=
在文本标签中,给定下划线的字符. 默认值是 -1, 意思是没有字符有下划线. (underline/Underline)
width=
按钮的宽度。若是按钮显示文本,则以文本单位给出大小。若是按钮显示图像,则以像素(或屏幕单元)给出大小。若是省略了大小,或者是零,则根据按钮内容计算。(width/Width)
wraplength=
肯定按钮的文本应什么时候被包装成多行。这是在屏幕单元中给出的。默认值为0(无包装)。 (wrapLength/WrapLength)
Canvas:油画(布),绘画板
config(**options) [#]
**options
background=
绘画板背景颜色。默认为标准的小器件背景色. (数据库名background, 类名Background)
bg=
Same as background.
borderwidth=
画图板边框的宽度。 默认值是0 (no border). (borderWidth/BorderWidth)
bd=
Same as borderwidth.
closeenough= 近距离感觉??
默认值是 1. (closeEnough/CloseEnough)
confine= 限制???
默认值是 1. (confine/Confine)
cursor=
鼠标移动到画图板上时显示的光标。(cursor/Cursor)
height=
画图板的高度。默认值是‘7c’. (height/Height)
highlightbackground=
当画布没有焦点时,用于高亮边框的颜色。默认值是系统指定. (highlightBackground/HighlightBackground)
highlightcolor=
当画布具备焦点时,用于高亮边框的颜色。默认值是系统指定. (highlightColor/HighlightColor)
highlightthickness=
突出边框的宽度。默认值是系统指定(一般是1到2个像素)(highlightThickness/HighlightThickness)
insertbackground=
文本插入光标所使用的颜色。默认值是系统指定. (insertBackground/Foreground)
insertborderwidth=
将插入光标的边框宽度。若是这被设置为非零值,光标是凸起边框样式绘制。 (insertBorderWidth/BorderWidth)
insertofftime=
与insertontime使用方式一致,这个选项控制光标闪烁。两个值都以毫秒为单位给出。 (insertOffTime/OffTime)
insertontime=
See insertofftime. (insertOnTime/OnTime)
insertwidth=
插入游标的宽度。一般是1/2个像素。 (insertWidth/InsertWidth)
offset= # 偏移
默认值是‘0,0’. (offset/Offset)
relief=
边框样式,默认值是FLAT. 其余值是SUNKEN, RAISED, GROOVE, and RIDGE. (relief/Relief)
scrollregion=
画布滚动区域。没有默认值。 (scrollRegion/ScrollRegion)
selectbackground=
选择背景色。 默认值是系统指定. (selectBackground/Foreground)
selectborderwidth=
选择边框宽度。默认值是系统指定. (selectBorderWidth/BorderWidth)
selectforeground=
选择文本颜色。默认值是系统指定. (selectForeground/Background)
state=
画布状态。NORMAL, DISABLED, or HIDDEN. 默认值是NORMAL. 注意:这是一个全局设置, 但个别画布项可使用项级状态选项来覆盖此设置。 (state/State)
takefocus=
指示用户可使用tab键移动到这个小部件。默认是一个空字符串,这意味着只有当它具备任何键盘绑定时,画布小部件才会接受焦点。(takeFocus/TakeFocus)
width=
画布宽度。默认值是‘10c’. (width/Width)
xscrollcommand=
用于链接一个画布水平滚动条。此选项应设置为相应的滚动条的设置方法。 (xScrollCommand/ScrollCommand)
xscrollincrement= 水平滚动增量
默认值是 0. (xScrollIncrement/ScrollIncrement)
yscrollcommand=
用于链接一个画布垂直滚动条。此选项应设置为相应的滚动条的设置方法。 (yScrollCommand/ScrollCommand)
yscrollincrement= 垂直滚动增量
默认值是 0. (yScrollIncrement/ScrollIncrement)
CheckBox: 复选框
config(**options) [#]
**options
activebackground=
按钮激活时使用的背景色。默认值是特定于系统的。(数据库名字activeBackground,类名Foreground)
activeforeground=
按钮激活时使用的前景色。默认值是特定于系统的。(activeForeground/Background)
anchor=
控件位于文本(或图像)的按钮所在位置。使用N, NE, E, SE, S, SW, W, NW, or CENTER之一. 默认CENTER.若是改变,也许也能够添加一些填充物,可使用padx and/or pady 参数. (anchor/Anchor)
background=
按钮背景颜色。默认值是特定于系统的。(background/Background)
bg=
Same as background.
bitmap=
要在小部件中显示的位图。若是给定图像选项,则忽略此选项。
你可使用一个内置的位图,或加载位图的XBM文件。要从文件加载位图,只需将文件名前缀为at标记(例如:“@sample.xbm”). (bitmap/Bitmap)
borderwidth=
按钮边框的宽度。默认值是特定于系统的,但一般是1/2个像素。(borderWidth/BorderWidth)
bd=
Same as borderwidth.
command=
按下按钮时调用的函数或方法。回调函数能够是函数、绑定方法,或者任何其余可调用的Python对象。没有默认。(command/Command)
compound= # 混合
没有默认值。(compound/Compound)
cursor=
鼠标指针在按钮上移动时显示的光标。(cursor/Cursor)
disabledforeground=
按钮禁用时使用的颜色。背景显示在背景色中。(disabledForeground/DisabledForeground)
font=
按钮中使用的字体。按钮只能包含单个字体的文本。默认值是特定于系统的。(font/Font)
foreground=
按钮前景色。默认值是特定于系统的。(foreground/Foreground)
fg=
Same as foreground.
height=
按钮的大小。若是按钮显示文本,则以文本单位给出大小。若是按钮显示图像,则以像素(或屏幕单元)给出大小。若是省略了大小,则基于按钮内容计算。 (height/Height)
highlightbackground=
默认值是特定于系统的。(highlightBackground/HighlightBackground)
highlightcolor=
默认值是特定于系统的。 (highlightColor/HighlightColor)
highlightthickness=
默认值是:1. (highlightThickness/HighlightThickness)
image=
要在小部件中显示的图像。若是指定,则优先于文本和位图选项。没有默认。 (image/Image)
indicatoron=
控制是否应绘制指示器。默认是打开的.
将此选项设置为false意味着将用做指示符。若是按钮被选中,将会被绘制为SUNKEN 代替RAISED. (indicatorOn/IndicatorOn)
justify=
定义如何对齐多行文本。 使用LEFT, RIGHT, or CENTER (default). (justify/Justify)
offrelief=
默认值是:raised 凸起. (offRelief/OffRelief)
offvalue=
未选中按钮相对应的值。默认值是0. (offValue/Value)
onvalue=
选中按钮对应的值,默认值是1. (onValue/Value)
overrelief=
无默认值. (overRelief/OverRelief)
padx=
按钮水平填充. 默认值是 1. (padX/Pad)
pady=
按钮垂直填充. 默认值是 1. (padY/Pad)
relief=
边框装饰。这一般是扁平FLAT的选择按钮,除非他们使用边界的指示(经过指标的选择)。 (relief/Relief)
selectcolor=
用于选择器的颜色。默认值是系统指定. (selectColor/Background)
selectimage=
用于选择器的图形图像。No default. (selectImage/SelectImage)
state=
按钮状态,可选NORMAL, ACTIVE or DISABLED. 默认值是 NORMAL. (state/State)
takefocus=
指示用户可使用tab键移动到该按钮。默认是一个空字符串,这意味着只有当它有任何键盘绑定时,按钮才会接受焦点(换句话说,默认是打开的)。(takeFocus/TakeFocus)
text=
要在按钮中显示的文本。文本能够包含换行。若是使用位图或图像选项,则忽略此选项。(text/Text)
textvariable=
按钮的Tkinter变量(一般是一个StringVar)。若是变量被更改,按钮文本将被更新。
还能够看到变量选项。 (textVariable/Variable)
underline=
要下划线的字符,若是有的话。默认值是 -1 (no underline). (underline/Underline)
variable=
把它变为按钮。按下按钮时,该变量是预测临界值和价值之间切换。按钮会自动反映对变量的显式更改。 (variable/Variable)
width=
按钮的宽度。(width/Width)
wraplength=
肯定按钮的文本应什么时候被包装成多行。这是在屏幕单元中给出的。默认是没有包装。 (wrapLength/WrapLength)
deselect() [#]
反选按钮。
flash() [#]
屡次重绘按钮, 激活与正常外观交替。
invoke() [#]
调用与按钮关联的命令。
select() [#]
选择按钮。
toggle() [#]
切换按钮。
Entry:输入框,跟input同样
config(**options) [#]
background=
控件的背景。默认值是特定于系统的。(参数数据库名字 background,类名字 Background)
bg=
Same as background.
borderwidth=
边框宽度。默认值是特定于系统的,但一般是几个像素。 (borderWidth/BorderWidth)
bd=
Same as borderwidth.
cursor=
控件的光标。默认值是文本插入游标。(一个典型的“I-beam工字钢”光标,如xterm). (cursor/Cursor)
disabledbackground=
当小部件被禁用时使用的背景。若是省略或空白,则使用标准背景。(disabledBackground/DisabledBackground)
disabledforeground=
控件被禁用时,文字颜色的使用。若是省略或空白,前景是用来代替标准。(disabledForeground/ DisabledForeground)
exportselection=
若是为真,所选文本将自动导出到剪贴板。默认为真。(exportSelection/ExportSelection)
font=
器件字体。系统指定. (font/Font)
foreground=
文本颜色。(foreground/Foreground)
fg=
Same as foreground.
highlightbackground=
与highlightcolor相同, 这个选项控制如何画重点突出边境。此选项在小部件没有焦点时使用。系统指定. (highlightBackground/HighlightBackground)
highlightcolor=
highlightbackground相同,但用于当控件具备焦点。(highlightColor/HighlightColor)
highlightthickness=
焦点突出边框的宽度。默认状况下,一般只有几个像素,除非系统经过修改按钮自己(好比在Windows上)表示焦点。 (highlightThickness/HighlightThickness)
insertbackground=
用于插入光标的颜色。(insertBackground/Foreground)
insertborderwidth=
插入游标边框的宽度。若是将此值设置为非零值,则使用RAISED 凸起边框样式绘制光标。(insertBorderWidth/BorderWidth)
insertofftime=
与insertontime相同,这个选项控制光标闪烁。两个值都以毫秒为单位给出。 (insertOffTime/OffTime)
insertontime=
See insertofftime. (insertOnTime/OnTime)
insertwidth=
插入游标的宽度。一般是一或两个像素。 (insertWidth/InsertWidth)
invalidcommand= 无效命令
FIXME. No default. (invalidCommand/InvalidCommand)
invcmd=
Same as invalidcommand.
justify=
如何对齐输入字段中的文本。使用 LEFT, CENTER, or RIGHT之一. 默认值 LEFT. (justify/Justify)
readonlybackground=
背景颜色使用状态“只读”。若是省略或空白,则使用标准背景。(readonlyBackground/ReadonlyBackground)
relief=
边框样式。默认值SUNKEN. 其余可选值:FLAT, RAISED, GROOVE, and RIDGE. (relief/Relief)
selectbackground=
选择背景色。默认是系统和显示特定的。(selectBackground/Foreground)
selectborderwidth=
选择边框宽度,系统指定. (selectBorderWidth/BorderWidth)te
selectforeground=
选择文本颜色,系统指定. (selectForeground/Background)
show=
控制如何显示小部件的内容。若是非空,则小部件显示字符字符串,而不是实际内容。要得到密码输入小部件,请将此选项设置为“*”。 (show/Show)
state=
输入框状态: NORMAL, DISABLED, or “readonly” (same as DISABLED,可是内容能够选择和拷贝). 默认值 NORMAL. 注意若是设置了DISABLED or “readonly”, 忽略插入和删除的调用。(state/State)
takefocus=
指示用户可使用tab键移动到这个小部件。默认是一个空字符串,这意味着只有当它具备任何键盘绑定(默认是打开的)时,输入框小部件才会接受焦点。 (takeFocus/TakeFocus)
textvariable=
把Tkinter变量(一般是一个StringVar)的输入字段的内容。(textVariable/Variable)
validate=
指定什么时候应该进行验证。你能够用“focus”来验证当控件得到或失去焦点,“focusin”进行验证,只有当它得到焦点,“focusout”验证失去焦点,“key”上的任何修改,和全部的状况。默认是没有的(没有验证)。 (validate/Validate)
validatecommand=
一个函数或方法调用检查内容是有效的。若是新内容的功能应该是有效的返回一个真值或假若是不是。请注意,此选项仅用于验证选项没有没有若是。 (validateCommand/ValidateCommand)
vcmd=
Same as validatecommand.
width=
输入字段的宽度,以字符单位为单位。注意,它控制屏幕上的大小;它不限制能够键入到输入字段中的字符数。默认宽度为20个字符。(width/Width)
xscrollcommand=
用来链接一个输入字段的水平滚动条。此选项应设置为相应的滚动条的设置方法。(xScrollCommand/ScrollCommand)
LabelFrame: 标签框架,就是能够将小器件抱起来的圈圈。
config(**options) [#]
**options
background=
此框架中使用的背景色。默认为应用程序背景颜色。若要防止更新,请将颜色设置为空字符串。 (the option database name is background, the class is Background)
bd=
Same as borderwidth.
bg=
Same as background.
borderwidth=
边框宽度。默认是2像素。 (borderWidth/BorderWidth)
class=
默认值是:Labelframe. (class/Class)
colormap=
有些显示器只支持256种颜色(有些甚至更少)。这种显示一般提供一个颜色映射来指定使用哪256种颜色。此选项容许您指定用于此帧的颜色映射及其子部件。
默认状况下,一个新框架使用与其父相同的颜色映射。使用此选项,您能够重用另外一个窗口的颜色映射(此窗口必须位于同一个屏幕上,且具备相同的视觉特性)。您也可使用值“新”来为这个框架分配一个新的颜色映射。
建立框架后,不能更改此选项。(colormap/Colormap)
container=
若是为true,则此frame是容器小部件。默认为false。
建立frame后,不能更改此选项。(container/Container)
cursor=
鼠标指针放置在这个小部件上时要显示的光标。默认值是特定于系统的箭头光标。 (cursor/Cursor)
fg=
Same as foreground.
font=
标签文本使用的字体。默认值是特定于系统的。(font/Font)
foreground=
用于标签文本的颜色。默认值是特定于系统的。(foreground/Foreground)
height=
Frame高度,以像素为单位。无默认值。 (height/Height)
highlightbackground=
与highlightcolor相同, 这个选项控制如何画重点突出边境。此选项在小部件没有焦点时使用。默认值是特定于系统的。 (highlightBackground/HighlightBackground)
highlightcolor=
与highlightbackground相同, 当小器件有焦点时使用. (highlightColor/HighlightColor)
highlightthickness=
焦点突出边框的宽度。默认值一般是几个像素。 (highlightThickness/HighlightThickness)
labelanchor=
在哪里画标签文本。默认是NW (upper left corner). (labelAnchor/LabelAnchor)
labelwidget=
用于标签的小部件。若是省略,框架使用文本选项。无默认值。(labelWidget/LabelWidget)
padx=
水平内填充。默认值 0. (padX/Pad)
pady=
垂直内填充。默认值 0. (padY/Pad)
relief=
边框样式。默认值GROOVE.其余值有FLAT, RAISED, SUNKEN, and RIDGE. (relief/Relief)
takefocus=
若是为true,则指示用户可使用tab键移动到这个小部件。默认值是0 (false). (takeFocus/TakeFocus)
text=
标签文本。 (text/Text)
visual=
视屏。无默认值。(visual/Visual)
width=
Frame 宽度.无默认值. (width/Width)
Menu:菜单
root = Tk()
def hello():
print "hello!"
menubar = Menu(root)
# create a pulldown menu, and add it to the menu bar
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command=hello)
filemenu.add_command(label="Save", command=hello)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
# create more pulldown menus
editmenu = Menu(menubar, tearoff=0)
editmenu.add_command(label="Cut", command=hello)
editmenu.add_command(label="Copy", command=hello)
editmenu.add_command(label="Paste", command=hello)
menubar.add_cascade(label="Edit", menu=editmenu)
helpmenu = Menu(menubar, tearoff=0)
helpmenu.add_command(label="About", command=hello)
menubar.add_cascade(label="Help", menu=helpmenu)
# display the menu
root.config(menu=menubar)
config(**options) [#]
**options
activebackground=
默认值‘SystemHighlight’. (数据库名字activeBackground, 类名字是 Foreground)
activeborderwidth=
默认值是 0. (activeBorderWidth/BorderWidth)
activeforeground=
默认值是 ‘SystemHighlightText’. (activeForeground/Background)
background=
默认值是 ‘SystemMenu’. (background/Background)
bg=
Same as background.
borderwidth=
默认值是 0. (borderWidth/BorderWidth)
bd=
Same as borderwidth.
cursor=
默认值是 ‘arrow’. (cursor/Cursor)
disabledforeground=
默认值是 ‘SystemDisabledText’. (disabledForeground/DisabledForeground)
font=
默认值是 ‘MS Sans Serif 8’. (font/Font)
foreground=
默认值是 ‘SystemMenuText’. (foreground/Foreground)
fg=
Same as foreground.
postcommand=
无默认值. (postCommand/Command)
relief=
默认值是 ‘flat’. (relief/Relief)
selectcolor=
默认值是 ‘SystemMenuText’. (selectColor/Background)
takefocus=
默认值是 0. (takeFocus/TakeFocus)
tearoff=
默认值是 1. (tearOff/TearOff)
tearoffcommand=
无默认值. (tearOffCommand/TearOffCommand)
title=
无默认值. (title/Title)
type=
默认值是 ‘normal’. (type/Type)
Menubutton : 菜单按钮
config(**options) [#]
activebackground=
默认值是系统指定. (the database name is activeBackground, the class is Foreground)
activeforeground=
默认值是系统指定. (activeForeground/Background)
anchor=
默认值是 CENTER. (anchor/Anchor)
background=
默认值是系统指定. (background/Background)
bg=
Same as background.
bitmap=
无默认值. (bitmap/Bitmap)
borderwidth=
默认值是 2. (borderWidth/BorderWidth)
bd=
Same as borderwidth.
compound=
默认值是NONE. (compound/Compound)
cursor=
无默认值. (cursor/Cursor)
direction=
默认值是“below”. (direction/Direction)
disabledforeground=
默认值是系统指定. (disabledForeground/DisabledForeground)
font=
默认值是系统指定. (font/Font)
foreground=
默认值是系统指定. (foreground/Foreground)
fg=
Same as foreground.
height=
默认值是 0. (height/Height)
highlightbackground=
默认值是系统指定. (highlightBackground/HighlightBackground)
highlightcolor=
默认值是系统指定. (highlightColor/HighlightColor)
highlightthickness=
默认值是 0. (highlightThickness/HighlightThickness)
image=
无默认值. (image/Image)
indicatoron=
默认值是 0. (indicatorOn/IndicatorOn)
justify=
默认值是 CENTER. (justify/Justify)
menu=
无默认值. (menu/Menu)
padx=
默认值是 ‘4p’. (padX/Pad)
pady=
默认值是 ‘3p’. (padY/Pad)
relief=
默认值是 FLAT. (relief/Relief)
state=
默认值是 NORMAL. (state/State)
takefocus=
默认值是 0. (takeFocus/TakeFocus)
text=
无默认值. (text/Text)
textvariable=
无默认值. (textVariable/Variable)
underline=
默认值是 -1 (no underline). (underline/Underline)
width=
默认值是 0. (width/Width)
wraplength=
默认值是 0. (wrapLength/WrapLength)
Message : 消息
消息控件的标签的一个变种,用来显示多行信息。消息小部件能够包装文本,并调整其宽度以维持给定的长宽比。
config(**options) [#]
**options
anchor=
在消息小部件中,文本的位置。使用N, NE, E, SE, S, SW, W, NW, or CENTER之一. 默认值 CENTER. (数据库名字anchor, 类名字 Anchor)
aspect=
宽高比,做为宽度/高度关系的百分比。默认值是150,这意味着消息将比它高50%。注意,若是显式设置了宽度,则忽略此选项。 (aspect/Aspect)
background=
Message背景颜色. 默认值是系统指定 (background/Background)
bg=
Same as background.
borderwidth=
边框宽度。默认值是2. (borderWidth/BorderWidth)
bd=
Same as borderwidth.
cursor=
鼠标移动到消息小部件时显示什么光标。默认值是使用标准游标。(cursor/Cursor)
font=
消息字体. 默认值是系统指定 (font/Font)
foreground=
文本颜色. 默认值是系统指定 (foreground/Foreground)
fg=
Same as foreground.
highlightbackground=
与highlightcolor和highlightthickness相同, 这个选项控制如何绘制高亮区域。(highlightBackground/HighlightBackground)
highlightcolor=
See highlightbackground. (highlightColor/HighlightColor)
highlightthickness=
See highlightbackground. (highlightThickness/HighlightThickness)
justify=
定义如何对齐多行文本。使用LEFT, RIGHT, or CENTER. 注意,要在小部件中定位文本,请使用锚点选项。默认值是LEFT. (justify/Justify)
padx=
水平填充。默认值是-1 (no padding). (padX/Pad)
pady=
垂直填充。默认值是-1 (no padding). (padY/Pad)
relief=
边框装饰。默认值是FLAT.其它选项是 SUNKEN, RAISED, GROOVE, and RIDGE. (relief/Relief)
takefocus=
若是为真,则小部件接受输入焦点。默认为false。(takeFocus/TakeFocus)
text=
消息文本。若是必要的话,小部件插入换行符以得到所要求的宽高比。 (text/Text)
textvariable=
把Tkinter变量(一般是一个StringVar)的消息。若是变量被更改,消息文本将被更新。(textVariable/Variable)
width=
部件宽度,字符单位。若是省略,小部件根据外观设置选择合适的宽度。 (width/Width)
PanedWindow : 中分栏窗口控件
config(**options) [#]
**options
background=
默认值是系统指定. (background/Background)
bd=
Same as borderwidth.
bg=
Same as background.
borderwidth=
默认值是 2. (borderWidth/BorderWidth)
cursor=
无默认值. (cursor/Cursor)
handlepad=
默认值是 8. (handlePad/HandlePad)
handlesize=
默认值是 8. (handleSize/HandleSize)
height=
无默认值. (height/Height)
opaqueresize=
无默认值. (opaqueResize/OpaqueResize)
orient=
默认值是 HORIZONTAL. (orient/Orient)
relief=
默认值是 FLAT. (relief/Relief)
sashcursor=
无默认值. (sashCursor/Cursor)
sashpad=
默认值是 2. (sashPad/SashPad)
sashrelief=
默认值是 RAISED. (sashRelief/Relief)
sashwidth=
默认值是 2. (sashWidth/Width)
showhandle=
无默认值. (showHandle/ShowHandle)
width=
无默认值. (width/Width)
Radiobutton:单选按钮
config(**options) [#]
**options
activebackground=
点击按钮是会使用的背景颜色,默认为系统指定的颜色,(参数的数据库名字是activeBackground,类是Foreground)
activeforeground=
按钮激活时使用什么前景色。默认值是特定于系统的。(activeForeground/Background)
anchor=
控件位于文本(或图像)的按钮所在位置。使用N, NE, E, SE, S, SW, W, NW, or CENTER. 默认 CENTER. (anchor/Anchor)
background=
背景色,默认是系统指定的颜色 (background/Background)
bg=
Same as background.
bitmap=
要在小部件中显示的位图。若是给定图像选项,则忽略此选项。 (bitmap/Bitmap)
borderwidth=
按钮边界宽度,默认值是平台指定的, 一般是1或2个像素. (borderWidth/BorderWidth)
bd=
Same as borderwidth.
command=
当按钮被点击是调用的方法或者函数. 回调函数能够是函数、绑定方法,或者任何其余可调用的Python对象。(command/Command)
compound=
控制如何将文本和图像组合在按钮中。默认状况下,若是给定一个图像或位图,则将其绘制为文本。若是将此选项设置为 CENTER ,则在图像顶部绘制文本。若是该选项设置为 BOTTOM, LEFT, RIGHT, or TOP ,则除文本以外绘制图像(使用 BOTTOM 绘制文本下的图像等)。默认没有。(compound/Compound)
cursor=
鼠标移动到按钮上时显示的光标。(cursor/Cursor)
disabledforeground=
按钮禁用时使用的颜色。背景显示在背景色中。默认值是特定于系统的。(disabledForeground/DisabledForeground)
font=
按钮中使用的字体。按钮只能包含单个字体的文本。默认值是特定于系统的。(font/Font)
foreground=
用于文本和位图内容的颜色。默认值是特定于系统的。(foreground/Foreground)
fg=
Same as foreground.
height=
按钮的高度。若是按钮显示文本,则以文本单位给出大小为准。若是按钮显示图像,则以像素(或屏幕单元)给出大小。若是省略了大小,则基于按钮内容计算。 (height/Height)
highlightbackground=
没有触动按钮时,其边界显示的高亮颜色. 默认为系统指定. (highlightBackground/HighlightBackground)
highlightcolor=
当按钮具备焦点时,用于高亮边框的颜色,默认为系统指定。 (highlightColor/HighlightColor)
highlightthickness=
突出边框的宽度。默认值是特定于系统的(一般是1或2个像素)。 (highlightThickness/HighlightThickness)
image=
要在小部件中显示的图像。若是指定,则优先于文本和位图选项。 (image/Image)
indicatoron=
若是为真,小部件使用标准单选按钮外观。若是为假,所选按钮绘制为SUNKEN 代替。默认为真。
justify=
定义如何对齐多行文本。使用LEFT, RIGHT, or CENTER. 默认是 CENTER. (justify/Justify)
offrelief=
默认值是 raised. (offRelief/OffRelief)
overrelief=
替代性救济使用,当鼠标移到窗口小部件。若是是空的,老是用减压阀。(overRelief/OverRelief)
padx=
文本或图像和边框之间的额外水平填充。(padX/Pad)
pady=
文本或图像和边框之间的额外垂直填充。(padY/Pad)
relief=
边框装饰。SUNKEN, RAISED, GROOVE, RIDGE, or FLAT.(凹陷的、凸起的、槽状的、脊状的或扁平的) 若是indicatoron真默认为扁平, 不然是凸起 RAISED. (relief/Relief)
selectcolor=
默认值是‘SystemWindow’. (selectColor/Background)
selectimage=
无默认值. (selectImage/SelectImage)
state=
按钮状态 NORMAL, ACTIVE or DISABLED. 默认是NORMAL. (state/State)
takefocus=
指示用户可使用tab键移动到该按钮。默认是一个空字符串,这意味着只有当它有任何键盘绑定时,按钮才会接受焦点(换句话说,默认是打开的)。 (takeFocus/TakeFocus)
text=
要在按钮中显示的文本。文本能够包含换行。若是使用位图或图像选项,则忽略此选项(除非使用复合选项)。 (text/Text)
textvariable=
把Tkinter变量(一般是一个StringVar)的按钮。若是变量被更改,按钮文本将被更新。(textVariable/Variable)
underline=
在文本标签中要下划线的字符。默认值是-1,意味着没有下划线。 (underline/Underline)
value=
这个按钮关联的值。同一组中的全部按钮都应该具备不一样的值。 (value/Value)
variable=
与此按钮关联的变量。为了得到适当的无线行为,您须要将同一变量与同一组中的全部按钮相关联。 (variable/Variable)
width=
按钮的宽度。若是按钮显示文本,则以文本单位给出大小。若是按钮显示图像,则以像素(或屏幕单元)给出大小。若是省略了大小,或者是零,则根据按钮内容计算。 (width/Width)
wraplength=
肯定按钮的文本应什么时候被包装成多行。这是在屏幕单元中给出的。默认值为0(无包装). (wrapLength/WrapLength)
deselect() [#]
取消选择button.
flash() [#]
频繁使用改变按钮时,可能会用到此方法
invoke() [#]
调用与按钮关联的命令。
select() [#]
选择button.
Scale : 规模、尺度、进度条
尺度小部件容许用户经过沿着标尺移动“滑块”旋钮来选择数值。您能够控制最小值和最大值,以及分辨率。
config(**options) [#]
**options
activebackground=
默认值是系统指定 (the database name is activeBackground, the class is Foreground)
background=
默认值是系统指定 (background/Background)
bg=
Same as background.
bigincrement=
默认值是0. (bigIncrement/BigIncrement)
borderwidth=
默认值是2. (borderWidth/BorderWidth)
bd=
Same as borderwidth.
command=
无默认值. (command/Command)
cursor=
无默认值. (cursor/Cursor)
digits=
默认值是0. (digits/Digits)
font=
默认值是系统指定 (font/Font)
foreground=
默认值是系统指定 (foreground/Foreground)
fg=
Same as foreground.
from=
默认值是0. (from/From)
highlightbackground=
默认值是系统指定 (highlightBackground/HighlightBackground)
highlightcolor=
默认值是系统指定 (highlightColor/HighlightColor)
highlightthickness=
默认值是2. (highlightThickness/HighlightThickness)
label=
无默认值. (label/Label)
length=
默认值是100. (length/Length)
orient=
默认值是VERTICAL. (orient/Orient)
relief=
默认值是FLAT. (relief/Relief)
repeatdelay=
默认值是300. (repeatDelay/RepeatDelay)
repeatinterval=
默认值是100. (repeatInterval/RepeatInterval)
resolution=
默认值是1. (resolution/Resolution)
showvalue=
默认值是1. (showValue/ShowValue)
sliderlength=
默认值是30. (sliderLength/SliderLength)
sliderrelief=
默认值是RAISED. (sliderRelief/SliderRelief)
state=
默认值是NORMAL. (state/State)
takefocus=
无默认值. (takeFocus/TakeFocus)
tickinterval=
默认值是0. (tickInterval/TickInterval)
to=
默认值是100. (to/To)
troughcolor=
默认值是系统指定 (troughColor/Background)
variable=
无默认值. (variable/Variable)
width=
默认值是15. (width/Width)
Scrollbar : 滚动条
滚动条控件几乎老是使用一个 Listbox, Canvas, or Text 。水平滚动条也可使用输入 Entry控件。
Scrollbar(master=None, **options) (class)
config(**options) [#]
**options
activebackground=
默认值是系统指定. (the database name is activeBackground, the class is Foreground)
activerelief=
默认值是 RAISED. (activeRelief/Relief)
background=
默认值是系统指定. (background/Background)
bg=
Same as background.
borderwidth=
边框宽度. 默认值是 0. (borderWidth/BorderWidth)
bd=
Same as borderwidth.
command=
用于更新关联小部件的回调。这是典型的滚动YView 或 XView部件的方法。
若是用户拖动滚动条滑块,该命令为回调命令。(“moveto”, offset), 其中偏移量0.0表示滑块处于最上面 (or leftmost) 位置, 偏移1.0意味着它在它的下面 (or rightmost) 位置.
若是用户单击箭头按钮,或者单击滚动槽中,则命令称为回调(“scroll”, step, what). 第二个参数是 “-1” 或者 “1” 视方向而定, 第三个参数是“units” 做为多行的滚动条 (或者其余有关单元的滚动部件), 或“pages” 做为整个页面的滚动条. (command/Command)
cursor=
光标显示当鼠标指针放在滚动条控件。默认值是特定于系统的箭头光标。(cursor/Cursor)
elementborderwidth=
默认值是 -1. (elementBorderWidth/BorderWidth)
highlightbackground=
与highlightcolor and highlightthickness相同,此选项控制如何绘制高亮边框。当小部件具备焦点时, a highlightthickness-wide 边框的绘制highlightcolor 的颜色。不然,它被绘制于highlightbackground 颜色. 默认颜色是特定于系统的颜色。(highlightBackground/HighlightBackground)
highlightcolor=
See highlightbackground. (highlightColor/HighlightColor)
highlightthickness=
See highlightbackground. 默认值是 0 (no highlight border). (highlightThickness/HighlightThickness)
jump=
默认值是 0. (jump/Jump)
orient=
定义如何绘制滚动条。使用HORIZONTAL or VERTICAL.默认值是VERTICAL. (orient/Orient)
relief=
边框装饰。默认值 SUNKEN.其余值能够选择FLAT, RAISED, GROOVE, and RIDGE. 在Windows下,忽略此选项. (relief/Relief)
repeatdelay=
默认值是 300. (repeatDelay/RepeatDelay)
repeatinterval=
默认值是 100. (repeatInterval/RepeatInterval)
takefocus=
默认值是空字符串. (takeFocus/TakeFocus)
troughcolor=
默认值是系统指定. (troughColor/Background)
width=
滚动条宽度,单位是像素.默认值是 16. (width/Width)
Label:标签
**options
Widget options.
activebackground=
当标签被激活时使用的背景色(能够设置状态选项). 默认值为平台指定的. (选项的数据库名activeBackground, 类名是Foreground)
activeforeground=
标签激活时使用什么前景色。默认为平台指定的颜色. (activeForeground/Background)
anchor=
控件在标签中的文本(或图像)应该位于何处。经过N, NE, E, SE, S, SW, W, NW, or CENTER设置. 默认是CENTER. (anchor/Anchor)
background=
背景颜色,默认是系统指定的. (background/Background)
bg=
Same as background.
bitmap=
要在小部件中显示的位图。若是给定图像选项,则忽略此选项。 (bitmap/Bitmap)
borderwidth=
标签边框的宽度。默认值是特定于系统的,但一般是一个或两个像素。 (borderWidth/BorderWidth)
bd=
Same as borderwidth.
compound=
控制如何将文本和图像组合在标签中。默认状况下,若是给定一个图像或位图,则将其绘制为文本。 若是参数设置为CENTER, 文本在图像的顶部绘制。若是参数被设置为BOTTOM, LEFT, RIGHT, or TOP之一, 图像被绘制在文本旁 (使用 BOTTOM 图像绘制在文本下, etc.)(compound/Compound)
cursor=
鼠标移动到标签上时显示什么光标。默认值是使用标准游标。 (cursor/Cursor)
disabledforeground=
当标签被禁用时使用什么前景色。默认值是特定于系统的。 (disabledForeground/ DisabledForeground)
font=
在标签中使用的字体. 标签中只包含单独字体的文本. 默认是系统指定的. (font/Font)
foreground=
使用文本和图像标签的前景色. 默认为系统指定. (foreground/Foreground)
fg=
Same as foreground.
height=
标签的高度. 若是展现的是文本,高度值将由文本给定。若是标签显示图像,则以像素(或屏幕单元)给出大小。若是大小设置为0,或者省略,则基于标签内容计算。 (height/Height)
highlightbackground=
当小部件没有焦点时,用于高亮边框的颜色是什么颜色?。默认值是特定于系统的,但一般与标准背景色相同。(highlightBackground/HighlightBackground)
highlightcolor=
当小部件具备焦点时,用于高亮边框的颜色是什么颜色?。默认值是特定于系统的。(highlightColor/HighlightColor)
highlightthickness=
突出边框的宽度。默认值为0(无高亮边框)。.(highlightThickness/HighlightThickness)
image=
要在小部件中显示的图像。该值应该是一个影像,bitmapimage,或兼容的对象。若是指定,则优先于文本和位图选项。(image/Image)
justify= 证实…有理;为…辩护;对…做出解释
定义如何对齐多行文本。使用LEFT, RIGHT, or CENTER.注意,要在小部件中定位文本,请使用锚点选项。默认值是 CENTER. (justify/Justify)
padx=
在文本周围添加额外的水平填充。默认值是1像素。(padX/Pad)
pady=
在文本周围添加额外的垂直填充。默认值是1像素。(padY/Pad)
relief=
边框装饰。默认是FLAT的。其余的值是SUNKEN, RAISED, GROOVE, and RIDGE. (relief/Relief)
state=
标签状态。此选项控制标签的呈现方式。默认值NORMAL. 还能够选择ACTIVE and DISABLED. (state/State)
takefocus=
若是为真,则小部件接受输入焦点。默认为false。(takeFocus/TakeFocus)
text=
在标签上显示的文本。文本能够包含换行。若是位图或图像选项,这个选项被忽略。(text/Text)
textvariable=
标签的Tkinter变量(一般是一个StringVar)。若是变量被更改,标签文本将被更新。(textVariable/Variable)
underline=
与文本选项一块儿使用,表示字符应加下划线(如键盘快捷键)。默认是-1 (没有下划线). (underline/Underline)
width=
标签的宽度。若是标签显示文本,则以文本单位给出大小。若是标签显示图像,则以像素(或屏幕单元)给出大小。若是大小设置为0,或者省略,则基于标签内容计算。(width/Width)
wraplength=
肯定什么时候将标签的文本包装成多行。这是在屏幕单元中给出的。默认值0 (没包装). (wrapLength/WrapLength)
photo = PhotoImage(file="icon.gif")
w = Label(parent, image=photo)
w.photo = photo
w.pack()
Listbox:列表框
config(**options) [#]
**options
Widget options.
activestyle=
默认是下划线. (参数数据库名字activeStyle, 类名字是ActiveStyle)
background=
默认值‘SystemButtonFace’. (background/Background)
bg=
Same as background.
borderwidth=
默认值 2. (borderWidth/BorderWidth)
bd=
Same as borderwidth.
cursor= 光标
无默认值. (cursor/Cursor)
disabledforeground= 禁用前景
默认是系统指定的。 (disabledForeground/DisabledForeground)
exportselection= 输出选择
默认自是1. (exportSelection/ExportSelection)
font=
默认为系统指定的字体. (font/Font)
foreground=
默认系统指定的前景色. (foreground/Foreground)
fg=
Same as foreground.
height=
默认高度10. (height/Height)
highlightbackground=
默认为系统指定的高亮背景色。 (highlightBackground/HighlightBackground)
highlightcolor=
默认为系统指定的高亮色。(highlightColor/HighlightColor)
highlightthickness=
高光厚度,默认值是1. (highlightThickness/HighlightThickness)
listvariable= 列表变量
无默认值. (listVariable/Variable)
relief=
边框装饰。默认是SUNKEN的。其余的值是FLAT, RAISED, GROOVE, and RIDGE. (relief/Relief)
selectbackground=
选择背景色,默认为系统指定. (selectBackground/Foreground)
selectborderwidth=
选择边框宽度,默认值为 1. (selectBorderWidth/BorderWidth)
selectforeground=
选择显示的前景色,默认为系统指定. (selectForeground/Background)
selectmode= 选择模式
默认值是:BROWSE. (selectMode/SelectMode)
setgrid= 设置网格
默认值是0. (setGrid/SetGrid)
state=
状态默认值是: NORMAL.还能够选择ACTIVE and DISABLED (state/State)
takefocus=
若是为真,则小部件接受输入焦点。无默认值,应该默认值为False (takeFocus/TakeFocus)
width=
宽度默认值为:20. (width/Width)
xscrollcommand=
水平滚动条命令,无默认值。 (xScrollCommand/ScrollCommand)
yscrollcommand=
垂直滚动条命令,无默认值 (yScrollCommand/ScrollCommand)
activate(index) [#]
激活给定下标的值(它将标有下划线)。激活项可参照使用激活下标。
index
指定下标.
get(first, last=None) [#]
从列表中获取一个或多个项。此函数返回与给定索引(或给定索引范围中的字符串)相对应的字符串。使用get(0,END)获取列表中全部项的列表。使用get(ACTIVE) 获取激活项(下划线).
first
返回第一项First.
last
Last返回最后一项.如不选择,返回单一项.
Returns:
字符串列表.
Spinbox : 纱箱
Spinbox(master=None, **options) (class) [#]
纱箱部件是标准Tkinter输入控件的一个变种,它能够用来从一个固定数量的价值选择。
config(**options) [#]
**options
activebackground=
默认值是系统指定 (activeBackground/Background)
background=
默认值是系统指定 (background/Background)
bd=
Same as borderwidth.
bg=
Same as background.
borderwidth=
边框宽度。一般是几像素,由系统指定. (borderWidth/BorderWidth)
buttonbackground=
背景色. 默认值是系统指定 (Button.background/Background)
buttoncursor=
当鼠标通过按钮时使用的光标. 无默认值. (Button.cursor/Cursor)
buttondownrelief=
抬起按钮时边框的样式. 默认值是 RAISED. (Button.relief/Relief)
buttonuprelief=
点下按钮时边框的样式. 默认值是 RAISED. (Button.relief/Relief)
command=
按钮点击时回调的函数或方法. 无默认值. (command/Command)
cursor=
当鼠标通过输入框时显示的光标. 默认值是文本插入光标 (一般是XTERM). (cursor/Cursor)
disabledbackground=
当失效时显示的背景色. 默认值是系统指定. (disabledBackground/DisabledBackground)
disabledforeground=
当失效时显示的文本颜色. 默认值是系统指定. (disabledForeground/DisabledForeground)
exportselection=
默认值是 True. (exportSelection/ExportSelection)
fg=
Same as foreground.
font=
使用的字体. 默认值是系统指定 (font/Font)
foreground=
文本颜色. 默认值是系统指定 (foreground/Foreground)
format=
字符串格式. 无默认值. (format/Format)
from=
最小值. 与to一块儿使用来限制纱箱的范围.
注意:from是python的关键字,在使用时要加一个下划线(from_). (from/From)
highlightbackground=
默认值是系统指定 (highlightBackground/HighlightBackground)
highlightcolor=
默认值是系统指定 (highlightColor/HighlightColor)
highlightthickness=
无默认值. (highlightThickness/HighlightThickness)
increment=
默认值是 1.0. (increment/Increment)
insertbackground=
光标插入使用的颜色. (insertBackground/Foreground)
insertborderwidth=
插入光标的宽度. 若是设定一个非零的值, 光标会使用RAISED 边框风格来绘制. (insertBorderWidth/BorderWidth)
insertofftime=
与insertontime相同, 参数控制光标绑定. 值以毫秒为单位. (insertOffTime/OffTime)
insertontime=
See insertofftime. (insertOnTime/OnTime)
insertwidth=
插入光标宽度. 一般是1/2个像素。 (insertWidth/InsertWidth)
invalidcommand=
无默认值. (invalidCommand/InvalidCommand)
invcmd=
Same as invalidcommand.
justify=
默认值是 LEFT. (justify/Justify)
readonlybackground=
默认值是系统指定 (readonlyBackground/ReadonlyBackground)
relief=
默认值是 SUNKEN. (relief/Relief)
repeatdelay=
与repeatinterval相同, 这个选项控制按钮自动重复间隔.值以毫秒为单位。 (repeatDelay/RepeatDelay)
repeatinterval=
See repeatdelay. (repeatInterval/RepeatInterval)
selectbackground=
默认值是系统指定 (selectBackground/Foreground)
selectborderwidth=
无默认值. (selectBorderWidth/BorderWidth)
selectforeground=
默认值是系统指定 (selectForeground/Background)
state=
值选择 NORMAL, DISABLED, or “readonly”. 默认值是 NORMAL. (state/State)
takefocus=
指示用户可使用tab键移动到这个小部件。默认值是空字符串,这意味着只有当它具备任何键盘绑定时,条目小部件才会接受焦点。 (默认是开启的). (takeFocus/TakeFocus)
textvariable=
无默认值. (textVariable/Variable)
to=
See from. (to/To)
validate=
校验模式. 默认值是 NONE. (validate/Validate)
validatecommand=
校验回调函数. 无默认值. (validateCommand/ValidateCommand)
values=
器件包含校验值的一个元组. 覆盖from/to/increment. (values/Values)
vcmd=
Same as validatecommand.
width=
宽, 以字符为单位. 默认值是 20. (width/Width)
wrap=
若是TRUE,向上和向下按钮将环绕。 (wrap/Wrap)
xscrollcommand=
用于链接一个纱箱水平滚动条。此选项应设置为相应的滚动条的设置方法。(xScrollCommand/ScrollCommand)
Text:文本
config(**options) [#]
**options
autoseparators=
默认值是 1. (autoSeparators/AutoSeparators)
background=
默认值是系统指定. (the database name is background, the class is Background)
bg=
Same as background.
borderwidth=
默认值是 2. (borderWidth/BorderWidth)
bd=
Same as borderwidth.
cursor=
默认值是 “xterm”. (cursor/Cursor)
exportselection=
默认值是 1. (exportSelection/ExportSelection)
font=
默认值是系统指定. (font/Font)
foreground=
默认值是系统指定. (foreground/Foreground)
fg=
Same as foreground.
height=
默认值是 24. (height/Height)
highlightbackground=
默认值是系统指定. (highlightBackground/HighlightBackground)
highlightcolor=
默认值是系统指定. (highlightColor/HighlightColor)
highlightthickness=
默认值是 0. (highlightThickness/HighlightThickness)
insertbackground=
默认值是系统指定. (insertBackground/Foreground)
insertborderwidth=
默认值是 0. (insertBorderWidth/BorderWidth)
insertofftime=
默认值是 300. (insertOffTime/OffTime)
insertontime=
默认值是 600. (insertOnTime/OnTime)
insertwidth=
默认值是 2. (insertWidth/InsertWidth)
maxundo=
默认值是 0. (maxUndo/MaxUndo)
padx=
默认值是 1. (padX/Pad)
pady=
默认值是 1. (padY/Pad)
relief=
默认值是 SUNKEN. (relief/Relief)
selectbackground=
默认值是系统指定. (selectBackground/Foreground)
selectborderwidth=
默认值是 0. (selectBorderWidth/BorderWidth)
selectforeground=
默认值是系统指定. (selectForeground/Background)
setgrid=
默认值是 0. (setGrid/SetGrid)
spacing1=
默认值是 0. (spacing1/Spacing)
spacing2=
默认值是 0. (spacing2/Spacing)
spacing3=
默认值是 0. (spacing3/Spacing)
state=
默认值是 NORMAL. (state/State)
tabs=
无默认值. (tabs/Tabs)
takefocus=
无默认值. (takeFocus/TakeFocus)
undo=
默认值是 0. (undo/Undo)
width=
默认值是 80. (width/Width)
wrap=
默认值是 CHAR. (wrap/Wrap)
xscrollcommand=
无默认值. (xScrollCommand/ScrollCommand)
yscrollcommand=
无默认值. (yScrollCommand/ScrollCommand)
针对bind_all方法的一些使用
1 关于bind_all方法,第一个参数对应的内容不少。我在这里尽量把经常使用的罗列一下,省得你们再去单独搜索。 2 3 bind_all('<KeyPress-Up>', eventhandler) 键盘方向键上键 4 bind_all('<KeyPress-Down>', eventhandler) 键盘方向键下键 5 bind_all('<KeyPress-Left>', eventhandler) 键盘方向键左键 6 bind_all('<KeyPress-Right>', eventhandler) 键盘方向键右键 7 bind_all('<KeyPress>', eventhandler) 键盘键位通用处理 8 bind_all('<Enter>', eventhandler) 按下Enter键 9 bind_all('a', eventhandler) 键盘小写字母a 10 bind_all('A', eventhandler) 键盘大写字母A 11 bind_all('<Control-A>', eventhandler) Control+shift+a 12 bind_all('<Control-a>', eventhandler) Control+a 13 bind_all('<Control-Alt-b>', eventhandler) Control+Alt+b 14 15 类似的,Tkinter支持下面这些按键。可是须要知道的是不支持 16 17 Control—Alt 18 19 Cancel/Break/BackSpace/Tab/Return/Sift_L/Shift_R/Control_L/Control_R/Alt_L/Alt_R/Pause 20 21 Caps_Loack/Escape/Prior(Page Up)/Next(Page Down)/End/Home/Left/Up/Right/Down/Print/Insert/Delete/ 22 23 F1-12/Num_Lock/Scroll_Lock
事件用字符串定义,有一个特殊的语法规则:
<modifier-type-detail>
type字段是最重要的,它指出了事件的种类,能够指定为Button,Key或者Enter,Configure等等。modifier和detail字段能够提供一些附加信息,在大多数状况下能够不指定。还有不少方法能够简化事件字符串,好比:为了匹配一个键盘键,你能够省略尖角括号,直接用 键 便可。除非它是空格 , 或自己就是尖括号。
让咱们来看看最经常使用的事件格式:
事件格式:
<Button-1>
一个鼠标点击事件。1表明左键,2表明中键,3表明右键。当你在一个widget上点击鼠标按键,tkinter会自动捕获并触发event,注意,当按键被抬起时才会执行handler。鼠标的位置(相对于widge)x,y会被发往event对象传入handler。你也能够这样:,<1>,它们是等价的。我比较喜欢这种方式。
<B1-Motion>
鼠标拖动事件。1表明按下左键拖动,2表明中键,3表明右键。一样的,鼠标的x,y会以event对象方式被送往handler。
<ButtonRelease-1>
鼠标按下以后释放
<Double-Button-1>
双击鼠标
<Enter>
注意,这里是鼠标指针进入到widget里,并非表明按下键盘上的Enter键。
<Leave>
和上面的进入对应,鼠标离开widget。
<FocusIn> <FocusOut>
<Return> <Cancel> <BackSpace> <Tab> <Shift_L> <Control_L> <Alt_L> <Home> <Left> <Up> <Right> <Down> <Delete> <F1> <F2>
这些按键都和键盘上的一一对应。
<Key>
随便一个按键,键值会以char的格式放入event对象。
a b c ... 1 2 ...
对应键盘上的按键
<Configure>
这个关键了,若是widget的大小改变了,或者是位置,新的大小(width和height)会打包到event发往handler。
from tkinter import * root = Tk() root.title("窗口测试") def eventhandler(event): if event.keysym == 'Left': print('左键') elif event.keysym == 'Right': print('右键!') elif event.keysym == 'Up': print('向上键!') elif event.keysym == 'Down': print('向下键。') elif event.keysym == 'b': print('b键。') else: print(event.keysym, '无效输入!') lab = Label(root, text='just a label') lab.bind_all('<KeyPress>', eventhandler) lab.pack() root.mainloop()
结果:
向上键!
右键!
向下键。
左键
右键!
b键。
Shift_L 无效输入!
B 无效输入!
Return 无效输入!
Return 无效输入!
?? 无效输入!
Shift_L 无效输入!
?? 无效输入!
s 无效输入!
f 无效输入!
大部分来自: http://effbot.org/tkinterbook/
还能够参考:https://docs.python.org/3/library/tkinter.ttk.html
仍然参考: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html
补充一个小知识
关于引用模块,引入类的使用方式
from .xx import xx
from ..xx import xx
会出现一些导入错误信息
文件夹被python解释器视做package须要知足两个条件:
一、文件夹中必须有 __init__.py文件,该文件能够为空,但必须存在该文件。
二、不能做为顶层模块来执行该文件夹中的py文件(即不能做为主函数的入口)。
或者采用系统路径扩展的方法
import sys
sys.path.append(r'../Common')
import CommonUtil
这样就能充分利用路径的变化,来进行引用。
或者设置环境变量PYTHONPATH。
在最新的python3.0中,还能够编写一个 .pth 的文件来记录路径,
程序在执行时,能够加载这个文件。至关于设置环境变量PYTHONPATH一种替代方案。
能够将其放在python安装目录的顶层。