Tkinter Class API Reference Contents
Tkinter Class API Reference
Tk Application Root
tkinter.Tk(screenName=None, baseName=None, className='Tk', useTk=True, sync=False, use=None)
Toplevel widget of Tk which represents mostly the main window of an application. It has an associated Tcl interpreter.
Global Methods:
Note: The following methods are available on all widgets, but work globally rather than acting on an individual widget. By convention, they are usually invoked on the application root window.
Standard Methods for All Widgets
Additional Methods for Ttk Widgets
identify(x, y) instate(statespec, callback=None, *args, **kw) state(statespec=None) |
Ttk (Themed) Widgets
tkinter.ttk.Button(master=None, **kw)
Ttk Button widget, displays a textual label and/or image, and evaluates a command when pressed.
invoke() |
tkinter.ttk.Checkbutton(master=None, **kw)
Ttk Checkbutton widget which is either in on- or off-state.
invoke() |
tkinter.ttk.Combobox(master=None, **kw)
Ttk Combobox widget combines a text field with a pop-down list of values.
current(newindex=None) delete(first, last=None) get() icursor(index) index(index) insert(index, string) set(value) validate() | |
scan_dragto(x) scan_mark(x) | |
selection_adjust(index) ... aka select_adjust selection_from(index) ... aka select_from selection_present() ... aka select_present selection_range(start, end) ... aka select_range selection_to(index) ... aka select_to | |
xview(*args) xview_moveto(fraction) xview_scroll(number, what) |
tkinter.ttk.Entry(master=None, widget=None, **kw)
Ttk Entry widget displays a one-line text string and allows that string to be edited by the user.
delete(first, last=None) get() icursor(index) index(index) insert(index, string) validate() | |
scan_dragto(x) scan_mark(x) | |
selection_adjust(index) ... aka select_adjust selection_from(index) ... aka select_from selection_present() ... aka select_present selection_range(start, end) ... aka select_range selection_to(index) ... aka select_to | |
xview(*args) xview_moveto(fraction) xview_scroll(number, what) |
tkinter.ttk.Frame(master=None, **kw)
Ttk Frame widget is a container, used to group other widgets together.
tkinter.ttk.Label(master=None, **kw)
Ttk Label widget displays a textual label and/or image.
tkinter.ttk.LabeledScale(master=None, variable=None, from_=0, to=10, **kw)
A Ttk Scale widget with a Ttk Label widget indicating its current value. The Ttk Scale can be accessed through instance.scale, and Ttk Label can be accessed through instance.label
value() |
tkinter.ttk.Labelframe(master=None, **kw)
Ttk Labelframe widget is a container used to group other widgets together. It has an optional label, which may be a plain text string or another widget.
tkinter.ttk.Menubutton(master=None, **kw)
Ttk Menubutton widget displays a textual label and/or image, and displays a menu when pressed.
tkinter.ttk.Notebook(master=None, **kw)
Ttk Notebook widget manages a collection of windows and displays a single one at a time.
add(child, **kw) hide(tab_id) index(tab_id) insert(pos, child, **kw) select(tab_id=None) tab(tab_id, option=None, **kw) tabs() | |
enable_traversal() |
tkinter.ttk.OptionMenu(master, variable, default=None, *values, **kwargs)
Themed OptionMenu, based after tkinter's OptionMenu, which allows the user to select a value from a menu.
set_menu() |
tkinter.ttk.Panedwindow(master=None, **kw)
Ttk Panedwindow widget displays a number of subwindows, stacked either vertically or horizontally.
add(child, **kw) insert(pos, child, **kw) pane(pane, option=None, **kw) panecget(child, option) paneconfigure(tagOrId, cnf=None, **kw) ... aka paneconfig panes() remove(child) ... aka forget sashpos(index, newpos=None) | |
proxy(*args) proxy_coord() proxy_forget() proxy_place(x, y) | |
sash(*args) sash_coord(index) sash_mark(index) sash_place(index, x, y) |
tkinter.ttk.Progressbar(master=None, **kw)
Ttk Progressbar widget shows the status of a long-running operation.
start(interval=None) step(amount=None) stop() |
tkinter.ttk.Radiobutton(master=None, **kw)
Ttk Radiobutton widgets are used in groups to show or change a set of mutually-exclusive options.
invoke() |
tkinter.ttk.Scale(master=None, **kw)
Ttk Scale widget is typically used to control the numeric value of a linked variable that varies uniformly over some range.
coords(value=None) get(x=None, y=None) set(value) |
tkinter.ttk.Scrollbar(master=None, **kw)
Ttk Scrollbar controls the viewport of a scrollable widget.
activate(index=None) delta(deltax, deltay) fraction(x, y) get() set(first, last) |
tkinter.ttk.Separator(master=None, **kw)
Ttk Separator widget displays a horizontal or vertical separator bar.
tkinter.ttk.Sizegrip(master=None, **kw)
Ttk Sizegrip allows the user to resize the containing toplevel window by pressing and dragging the grip.
tkinter.ttk.Spinbox(master=None, **kw)
Ttk Spinbox is an Entry with increment and decrement arrows It is commonly used for number entry or to select from a list of string values.
delete(first, last=None) get() icursor(index) index(index) insert(index, string) set(value) validate() | |
scan_dragto(x) scan_mark(x) | |
selection_adjust(index) ... aka select_adjust selection_from(index) ... aka select_from selection_present() ... aka select_present selection_range(start, end) ... aka select_range selection_to(index) ... aka select_to | |
xview(*args) xview_moveto(fraction) xview_scroll(number, what) |
tkinter.ttk.Treeview(master=None, **kw)
Ttk Treeview widget displays a hierarchical collection of items.
column(column, option=None, **kw) delete(*items) detach(*items) exists(item) heading(column, option=None, **kw) index(item) insert(parent, index, iid=None, **kw) item(item, option=None, **kw) move(item, parent, index) ... aka reattach next(item) parent(item) prev(item) see(item) | |
get_children(item=None) | |
identify_column(x) identify_element(x, y) identify_region(x, y) identify_row(y) | |
selection() selection_add(*items) selection_remove(*items) selection_set(*items) selection_toggle(*items) | |
set(item, column=None, value=None) set_children(item, *newchildren) | |
tag_bind(tagname, sequence=None, callback=None) tag_configure(tagname, option=None, **kw) tag_has(tagname, item=None) | |
xview(*args) xview_moveto(fraction) xview_scroll(number, what) | |
yview(*args) yview_moveto(fraction) yview_scroll(number, what) |
Classic Widgets with no Themed Counterpart
tkinter.Canvas(master=None, cnf={}, **kw)
Canvas widget to display graphical elements like lines or text.
canvasx(screenx, gridspacing=None) canvasy(screeny, gridspacing=None) coords(*args) dchars(*args) delete(*args) dtag(*args) gettags(*args) icursor(*args) index(*args) insert(*args) itemcget(tagOrId, option) itemconfigure(tagOrId, cnf=None, **kw) ... aka itemconfig move(*args) moveto(tagOrId, x='', y='') postscript(cnf={}, **kw) scale(*args) type(tagOrId) | |
addtag(*args) addtag_above(newtag, tagOrId) addtag_all(newtag) addtag_below(newtag, tagOrId) addtag_closest(newtag, x, y, halo=None, start=None) addtag_enclosed(newtag, x1, y1, x2, y2) addtag_overlapping(newtag, x1, y1, x2, y2) addtag_withtag(newtag, tagOrId) | |
create_arc(*args, **kw) create_bitmap(*args, **kw) create_image(*args, **kw) create_line(*args, **kw) create_oval(*args, **kw) create_polygon(*args, **kw) create_rectangle(*args, **kw) create_text(*args, **kw) create_window(*args, **kw) | |
find(*args) find_above(tagOrId) find_all() find_below(tagOrId) find_closest(x, y, halo=None, start=None) find_enclosed(x1, y1, x2, y2) find_overlapping(x1, y1, x2, y2) find_withtag(tagOrId) | |
scan_dragto(x, y, gain=10) scan_mark(x, y) | |
select_adjust(tagOrId, index) select_clear() select_from(tagOrId, index) select_item() select_to(tagOrId, index) | |
tag_bind(tagOrId, sequence=None, func=None, add=None) tag_lower(*args) ... aka lower tag_raise(*args) ... aka tkraise tag_unbind(tagOrId, sequence, funcid=None) | |
xview(*args) xview_moveto(fraction) xview_scroll(number, what) | |
yview(*args) yview_moveto(fraction) yview_scroll(number, what) |
tkinter.Listbox(master=None, cnf={}, **kw)
Listbox widget which can display a list of strings.
activate(index) curselection() delete(first, last=None) get(first, last=None) index(index) insert(index, *elements) itemcget(index, option) itemconfigure(index, cnf=None, **kw) ... aka itemconfig nearest(y) see(index) | |
scan_dragto(x, y) scan_mark(x, y) | |
selection_anchor(index) ... aka select_anchor selection_includes(index) ... aka select_includes selection_set(first, last=None) ... aka select_set | |
xview(*args) xview_moveto(fraction) xview_scroll(number, what) | |
yview(*args) yview_moveto(fraction) yview_scroll(number, what) |
tkinter.Menu(master=None, cnf={}, **kw)
Menu widget which allows displaying menu bars, pull-down menus and pop-up menus.
activate(index) delete(index1, index2=None) entrycget(index, option) entryconfigure(index, cnf=None, **kw) ... aka entryconfig index(index) invoke(index) post(x, y) type(index) unpost() xposition(index) yposition(index) | |
add(itemType, cnf={}, **kw) add_cascade(cnf={}, **kw) add_checkbutton(cnf={}, **kw) add_command(cnf={}, **kw) add_radiobutton(cnf={}, **kw) add_separator(cnf={}, **kw) | |
insert(index, itemType, cnf={}, **kw) insert_cascade(index, cnf={}, **kw) insert_checkbutton(index, cnf={}, **kw) insert_command(index, cnf={}, **kw) insert_radiobutton(index, cnf={}, **kw) insert_separator(index, cnf={}, **kw) | |
tk_popup(x, y, entry='') |
tkinter.Text(master=None, cnf={}, **kw)
Text widget which can display text in various forms.
compare(index1, op, index2) count(index1, index2, *args) debug(boolean=None) delete(index1, index2=None) dlineinfo(index) dump(index1, index2=None, command=None, **kw) get(index1, index2=None) index(index) insert(index, chars, *args) replace(index1, index2, chars, *args) search(pattern, index, stopindex=None, forwards=None, backwards=None, exact=None, regexp=None, nocase=None, count=None, elide=None) see(index) | |
edit(*args) edit_modified(arg=None) edit_redo() edit_reset() edit_separator() edit_undo() | |
image_cget(index, option) image_configure(index, cnf=None, **kw) image_create(index, cnf={}, **kw) | |
mark_gravity(markName, direction=None) mark_names() mark_next(index) mark_previous(index) mark_set(markName, index) mark_unset(*markNames) | |
peer_create(newPathName, cnf={}, **kw) peer_names() | |
scan_dragto(x, y) scan_mark(x, y) | |
tag_add(tagName, index1, *args) tag_bind(tagName, sequence, func, add=None) tag_cget(tagName, option) tag_configure(tagName, cnf=None, **kw) ... aka tag_config tag_delete(*tagNames) tag_lower(tagName, belowThis=None) tag_names(index=None) tag_nextrange(tagName, index1, index2=None) tag_prevrange(tagName, index1, index2=None) tag_raise(tagName, aboveThis=None) tag_ranges(tagName) tag_remove(tagName, index1, index2=None) tag_unbind(tagName, sequence, funcid=None) | |
window_cget(index, option) window_configure(index, cnf=None, **kw) ... aka window_config window_create(index, cnf={}, **kw) window_names() | |
xview(*args) xview_moveto(fraction) xview_scroll(number, what) | |
yview(*args) yview_moveto(fraction) yview_pickplace(*what) yview_scroll(number, what) |
tkinter.Toplevel(master=None, cnf={}, **kw)
Toplevel widget, e.g. for dialogs.
wm_aspect(minNumer=None, minDenom=None, maxNumer=None, maxDenom=None) ... aka aspect wm_attributes(*args) ... aka attributes wm_client(name=None) ... aka client wm_colormapwindows(*wlist) ... aka colormapwindows wm_command(value=None) ... aka command wm_deiconify() ... aka deiconify wm_focusmodel(model=None) ... aka focusmodel wm_forget(window) ... aka forget wm_frame() ... aka frame wm_geometry(newGeometry=None) ... aka geometry wm_grid(baseWidth=None, baseHeight=None, widthInc=None, heightInc=None) ... aka grid wm_group(pathName=None) ... aka group wm_iconbitmap(bitmap=None, default=None) ... aka iconbitmap wm_iconify() ... aka iconify wm_iconmask(bitmap=None) ... aka iconmask wm_iconname(newName=None) ... aka iconname wm_iconphoto(default=False, *args) ... aka iconphoto wm_iconposition(x=None, y=None) ... aka iconposition wm_iconwindow(pathName=None) ... aka iconwindow wm_manage(widget) ... aka manage wm_maxsize(width=None, height=None) ... aka maxsize wm_minsize(width=None, height=None) ... aka minsize wm_overrideredirect(boolean=None) ... aka overrideredirect wm_positionfrom(who=None) ... aka positionfrom wm_protocol(name=None, func=None) ... aka protocol wm_resizable(width=None, height=None) ... aka resizable wm_sizefrom(who=None) ... aka sizefrom wm_state(newstate=None) ... aka state wm_title(string=None) ... aka title wm_transient(master=None) ... aka transient wm_withdraw() ... aka withdraw |
Classic Widgets Where a Themed Replacement is Available
tkinter.Button(master=None, cnf={}, **kw)
Button widget.
flash() invoke() |
tkinter.Checkbutton(master=None, cnf={}, **kw)
Checkbutton widget which is either in on- or off-state.
deselect() flash() invoke() select() toggle() |
tkinter.Entry(master=None, cnf={}, **kw)
Entry widget which allows displaying simple text.
delete(first, last=None) get() icursor(index) index(index) insert(index, string) | |
scan_dragto(x) scan_mark(x) | |
selection_adjust(index) ... aka select_adjust selection_from(index) ... aka select_from selection_present() ... aka select_present selection_range(start, end) ... aka select_range selection_to(index) ... aka select_to | |
xview(*args) xview_moveto(fraction) xview_scroll(number, what) |
tkinter.Frame(master=None, cnf={}, **kw)
Frame widget which may contain other widgets and can have a 3D border.
tkinter.Label(master=None, cnf={}, **kw)
Label widget which can display text and bitmaps.
tkinter.LabelFrame(master=None, cnf={}, **kw)
labelframe widget.
tkinter.Menubutton(master=None, cnf={}, **kw)
Menubutton widget, obsolete since Tk8.0.
tkinter.Message(master=None, cnf={}, **kw)
Message widget to display multiline text. Obsolete since Label does it too.
tkinter.OptionMenu(master, variable, value, *values, **kwargs)
OptionMenu which allows the user to select a value from a menu.
tkinter.PanedWindow(master=None, cnf={}, **kw)
panedwindow widget.
add(child, **kw) identify(x, y) panecget(child, option) paneconfigure(tagOrId, cnf=None, **kw) ... aka paneconfig panes() remove(child) ... aka forget | |
proxy(*args) proxy_coord() proxy_forget() proxy_place(x, y) | |
sash(*args) sash_coord(index) sash_mark(index) sash_place(index, x, y) |
tkinter.Radiobutton(master=None, cnf={}, **kw)
Radiobutton widget which shows only one of several buttons in on-state.
deselect() flash() invoke() select() |
tkinter.Scale(master=None, cnf={}, **kw)
Scale widget which can display a numerical scale.
coords(value=None) get() identify(x, y) set(value) |
tkinter.Scrollbar(master=None, cnf={}, **kw)
Scrollbar widget which displays a slider at a certain position.
activate(index=None) delta(deltax, deltay) fraction(x, y) get() identify(x, y) set(first, last) |
tkinter.Spinbox(master=None, cnf={}, **kw)
spinbox widget.
delete(first, last=None) get() icursor(index) identify(x, y) index(index) insert(index, s) invoke(element) | |
scan(*args) scan_dragto(x) scan_mark(x) | |
selection(*args) selection_adjust(index) selection_element(element=None) selection_from(index) selection_present() selection_range(start, end) selection_to(index) | |
xview(*args) xview_moveto(fraction) xview_scroll(number, what) |
Additional Classes
Variables
tkinter.Variable(master=None, value=None, name=None)
Class to define value holders for e.g. buttons. Subclasses StringVar, IntVar, DoubleVar, BooleanVar are specializations that constrain the type of the value returned from get().
tkinter.BooleanVar(master=None, value=None, name=None)
Value holder for boolean variables.
tkinter.DoubleVar(master=None, value=None, name=None)
Value holder for float variables.
tkinter.IntVar(master=None, value=None, name=None)
Value holder for integer variables.
tkinter.StringVar(master=None, value=None, name=None)
Value holder for strings variables.
get() set(value) ... aka initialize | |
trace_add(mode, callback) trace_info() trace_remove(mode, cbname) trace_variable(mode, callback) ... aka trace trace_vdelete(mode, cbname) trace_vinfo() |
Images
tkinter.BitmapImage(name=None, cnf={}, master=None, **kw)
Widget which can display images in XBM format.
configure(**kw) ... aka config height() type() width() |
tkinter.PhotoImage(name=None, cnf={}, master=None, **kw)
Widget which can display images in PGM, PPM, GIF, PNG format.
blank() cget(option) configure(**kw) ... aka config copy() get(x, y) height() put(data, to=None) subsample(x, y='') type() width() write(filename, format=None, from_coords=None) zoom(x, y='') | |
transparency_get(x, y) transparency_set(x, y, boolean) |
Dialogs
tkinter.filedialog.Directory(master=None, **options)
Ask for a directory
command() show(**options) |
tkinter.filedialog.Open(master=None, **options)
Ask for a filename to open
command() show(**options) |
tkinter.filedialog.SaveAs(master=None, **options)
Ask for a filename to save as
command() show(**options) |
tkinter.colorchooser.Chooser(master=None, **options)
Create a dialog for the tk_chooseColor command.
command() show(**options) |
Other
tkinter.ttk.Style(master=None)
Manipulate style database.
configure(style, query_opt=None, **kw) layout(style, layoutspec=None) lookup(style, option, state=None, default=None) map(style, query_opt=None, **kw) | |
element_create(elementname, etype, *args, **kw) element_names() element_options(elementname) | |
theme_create(themename, parent=None, settings=None) theme_names() theme_settings(themename, settings) theme_use(themename=None) |
tkinter.font.Font(root=None, font=None, name=None, exists=False, **options)
Represents a named font.
actual(option=None, displayof=None) cget(option) config(**options) ... aka configure copy() counter() measure(text, displayof=None) metrics(*options, **kw) |