574 Commits
Author SHA1 Message Date
Serhiy Storchaka 3736342e38 gh-157676: Fix KeyError in tkinter.simpledialog when a foreign window holds the grab (GH-157677)
_temp_grab_focus() used grab_current() and focus_get(), which raise
KeyError for windows which were not created by tkinter, such as a
native message box.  Use Tcl window names instead of widgets.

Regression from GH-151848, not present in released versions.
2026-09-29 15:56:42 +03:00
Serhiy StorchakaandClaude Opus 5 4a5a7b9f6d gh-157514: Add structured version info for tkinter (GH-157516)
Add constants tkinter.TCL_VERSION_INFO and tkinter.TK_VERSION_INFO,
named tuples with the versions of the Tcl and Tk libraries that were
used for building the module, and _tkinter.TCL_PATCH_LEVEL and
_tkinter.TK_PATCH_LEVEL strings.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-29 15:55:12 +03:00
Serhiy Storchaka 62cbd34df7 gh-156961: Fix tkinter.font.Font for a font name returned as a Tcl object (GH-157028)
Tk can return a font name or description as a Tcl object, for example
from ttk.Style().lookup("TButton", "font"), Menu.entrycget("font"),
ttk.Entry.cget("font"), or the default value in the result of
configure().  Such an object does not compare equal to a string, so it
was not recognized as the name of an existing named font.  Keep it as
is, so that it is passed back to Tk, and only convert it where it is
compared with a string.
2026-09-13 11:03:08 +03:00
Serhiy StorchakaandClaude Opus 4.8 77cb7560c0 gh-86726: Fix and improve tkinter documentation and docstrings (GH-153549)
Correct inaccurate return-type and option descriptions in the tkinter
reference, and add missing module and class docstrings.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 09:46:06 +00:00
Serhiy StorchakaandClaude Opus 4.8 93128f52f2 gh-50409: Modernize tkinter.PanedWindow.paneconfigure() (GH-152399)
Rename the first parameter of paneconfigure() (and its paneconfig alias)
from 'tagOrId' to 'child', for consistency with add(), remove() and
panecget() -- PanedWindow panes are child widgets, not tagged items.  The
old 'tagOrId' keyword still works but raises DeprecationWarning.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 06:01:54 +00:00
Serhiy StorchakaandClaude Opus 4.8 f212f219a5 gh-152638: Deprecate tkinter.filedialog.askopenfiles() (GH-152647)
Opening several files at once is error-prone, and the returned list
cannot be used in a "with" statement.  Iterate over the names returned
by askopenfilenames() and open them one by one instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 05:53:02 +00:00
Serhiy StorchakaandClaude Opus 4.8 b39dfe266e gh-72880: Add tkinter.fontchooser -- interface to the font selection dialog (GH-153255)
The FontChooser class wraps the "tk fontchooser" command.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 05:50:08 +00:00
Serhiy StorchakaandClaude Opus 4.8 342e5a4218 gh-153259: Add tkinter.systray -- system tray icon and notifications (GH-153260)
Add the tkinter.systray module with the SysTrayIcon class wrapping the
"tk systray" command and the notify() function wrapping "tk sysnotify"
(Tk 8.7/9.0 and newer).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 08:34:13 +03:00
Serhiy StorchakaandClaude Opus 4.8 45fa07b025 gh-153256: Add tk_print() methods to tkinter Canvas and Text (GH-153257)
The native print dialog (the "tk print" command, Tk 8.7/9.0+) only
supports canvas and text widgets, so expose it as a method of Canvas
and Text rather than of Misc.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-11 05:12:52 +00:00
tonghuaroot (童话) bac73b0f4e gh-153333: Read tkinter profile scripts with the source file's encoding (GH-153334)
Tk.readprofile ran the user's ~/.CLASS.py and ~/.BASE.py scripts with
exec(open(path).read()), decoding them with the locale encoding.  Read
them in binary mode so exec() honors each script's own coding cookie.
2026-07-11 04:42:35 +00:00
Serhiy StorchakaandClaude Opus 4.8 fbce45b587 gh-59396: Add use_ttk parameter to tkinter ScrolledText (GH-153119)
ScrolledText gained a keyword-only use_ttk parameter to build the
surrounding frame and the vertical scroll bar from the themed
tkinter.ttk widgets instead of the classic tkinter widgets.  The
classic widgets remain the default.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-10 17:16:53 +00:00
Serhiy Storchaka c59c95f7b4 gh-143070: Use "+" instead of "!" in automatically generated tkinter widget names (GH-151975)
The "!" prefix has a special meaning in the tag expressions of the
canvas and text widgets ("!", "&&", "||", "^" and parentheses), so an
automatically generated widget name could not be used as a tag.  "+" has
no special meaning there, nor in option database patterns or Tcl lists,
and a user is very unlikely to start an explicit name with it.
2026-07-10 19:36:12 +03:00
Serhiy StorchakaandClaude Opus 4.8 dd8739a35b gh-153422: Return bool from some tkinter query methods (GH-153429)
The winfo_exists(), winfo_ismapped() and winfo_viewable() methods of
tkinter widgets and Text.edit_modified() now return a bool instead of an
integer or, depending on wantobjects, a string.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-09 14:13:42 +00:00
Serhiy StorchakaandClaude Opus 4.8 45010f441d gh-143990: Preserve the size when creating a Font from a named font (GH-153267)
tkinter.font.Font now copies the options of a named font (via "font
configure") instead of the options resolved by "font actual", which
would resolve a size specified in pixels (a negative size) to points.
A font description is still resolved, as it cannot be parsed otherwise.

Font.copy(), which has always been equivalent to constructing a Font
from the original font, is updated to match and now preserves the size
too.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 11:30:12 +03:00
Serhiy StorchakaandClaude Opus 4.8 2cd5b79284 gh-143990: Allow tkinter.font.Font to wrap a font description (GH-152025)
With exists=True and no name, Font now wraps the font description as is,
without creating a new named font, so that it is used without loss of
precision by actual(), measure() and metrics().  Its name attribute is then
the description rather than a string.  Keyword options now override the
corresponding settings of the given font instead of being ignored.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-07 09:37:04 +00:00
Serhiy StorchakaandClaude Opus 4.8 8f06112b8f gh-43699: Defer the drag cursor in tkinter.dnd until the pointer moves (GH-152371)
The drag cursor is now changed only once the pointer starts moving past
a small threshold rather than on the initial button press, so that a
plain click no longer flashes it.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-05 15:49:43 +03:00
Serhiy StorchakaandClaude Opus 4.8 3d9d6c8ccb gh-59396: Use themed widgets in tkinter.filedialog (GH-152036)
The FileDialog, LoadFileDialog and SaveFileDialog dialogs are now built from
the themed tkinter.ttk widgets by default instead of the classic tkinter
widgets, and gained a use_ttk parameter that selects between the classic Tk
widgets and the themed ttk widgets.

They were also brought closer to the native Tk file dialog: the buttons and
field labels gained Alt key accelerators, the default ring follows the keyboard
focus, the Escape key cancels the dialog, the focus traverses the widgets in
their visual order, and the directory and file lists gained a horizontal
scrollbar and type-ahead selection.  The dialog is now transient and centered
over its parent, and the SaveFileDialog overwrite confirmation uses a themed
message box.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-05 14:27:51 +03:00
edcc07d985 gh-103878: Return a consistent empty value from cancelled file dialogs (GH-152435)
On cancellation Tcl may report the empty result as '', () or b'' depending
on the platform and Tk version. Normalize it so that askopenfilename(),
asksaveasfilename() and askdirectory() always return '' and
askopenfilenames() always returns ().

Open._fixresult() now distinguishes single from multiple results by the
'multiple' option rather than the result type.

Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 20:49:19 +00:00
Serhiy StorchakaandClaude Opus 4.8 9751e1d7df gh-152587: Make name and value required in tkinter variable methods (GH-152595)
The name parameter of Misc.wait_variable(), setvar() and getvar() and the
value parameter of setvar() no longer have default values, which were not
meaningful ('PY_VAR' and '1').

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-29 14:11:03 +00:00
Serhiy StorchakaandClaude Opus 4.8 ba0c0e6be1 gh-78335: Complete the widget option lists in tkinter docstrings (GH-152485)
Several widget __init__ docstrings omitted valid options, and Menubutton and
Message had no option list at all.  List every option supported by the widget,
tagging those added in Tk 9.0 and 9.1.

Add test_options_in_docstring, asserting that every option in OPTIONS is named
in the widget's __init__ docstring.  Options reported by keys() but not in the
docstring are only printed in verbose mode, as some depend on the Tk version.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 19:14:27 +03:00
Serhiy StorchakaandClaude Opus 4.8 ea7f64a65c gh-82830: Improve tkinter messagebox docstrings and cursor documentation (GH-152380)
Document Windows cursor files (gh-99089).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 14:01:34 +03:00
Serhiy StorchakaandClaude Opus 4.8 5c3555bdc5 gh-38464: Make tkinter nametowidget() work with cloned menus (GH-152336)
Map the auto-generated name of a cloned menu (a menu used as a menubar
or a cascade) back to the original widget instead of raising KeyError.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 02:02:52 +03:00
Serhiy StorchakaandClaude Opus 4.8 5fed5ce85d gh-88758: Handle non-tkinter widgets in tkinter focus methods (GH-152337)
focus_get(), focus_displayof(), focus_lastfor() and winfo_containing()
now return None instead of raising KeyError when the focused widget was
not created by tkinter (for example a torn-off menu).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-27 02:00:38 +03:00
Serhiy StorchakaandClaude Opus 4.8 deeae2ac07 gh-127802: Schedule removal of legacy tkinter variable trace methods in 3.17 (GH-152012)
The tkinter.Variable methods trace_variable(), trace(), trace_vdelete()
and trace_vinfo(), deprecated since Python 3.14, are now scheduled for
removal in Python 3.17.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-25 15:05:46 +03:00
Serhiy StorchakaandClaude Opus 4.8 ad38cf8292 gh-59396: Modernize tkinter.simpledialog (GH-151848)
Rework SimpleDialog and Dialog to match the look and feel of the native Tk
dialogs ::tk_dialog and ::tk::MessageBox.

* SimpleDialog is a Python port of ::tk_dialog and Dialog a base class
  modelled on ::tk::MessageBox.  Both adopt the message-box keyboard
  conventions: button accelerators, a default ring that follows the keyboard
  focus, and a <Return> binding that invokes the focused button.
* Both classes gain a use_ttk parameter that selects the classic Tk or the
  themed ttk widgets.  It controls the widget set and the appearance that the
  two procedures style differently, but not the keyboard behaviour.
* Update _place_window with the Tk 9.1 placement refinements.
* The new helpers _temp_grab_focus (a modal grab/focus context manager),
  _underline_ampersand and _find_alt_key_target (ports of the Tk
  accelerator-key procedures) can be reused by other tkinter dialogs, as
  _setup_dialog already is.
* Fix several defects uncovered while comparing with the Tcl sources.
* Improve the simpledialog demo.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 11:01:10 +03:00
Serhiy StorchakaandClaude Opus 4.8 868d9a82ca gh-101284: Allow passing Menubutton options to tkinter.OptionMenu (GH-151959)
Arbitrary keyword arguments are now forwarded to the underlying
Menubutton and can override OptionMenu's default appearance options.
The positional API is unchanged.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-23 06:24:17 +00:00
Serhiy Storchaka 3f09a175ad gh-75666: Fix a reference leak in tkinter event bindings (GH-151808)
The Tcl commands created for event callbacks are now deleted when a
binding is replaced or unbound, instead of being leaked.
2026-06-23 06:59:25 +03:00
Serhiy StorchakaandClaude Opus 4.8 27148d0857 gh-151920: Add the ttk.Style.theme_styles() method (GH-151921)
Wrap the Tk 9.0 ``ttk::style theme styles ?themeName?`` subcommand as
ttk.Style.theme_styles(themename=None), returning the list of styles
defined in a theme (the current theme if themename is omitted).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 20:43:43 +03:00
Serhiy StorchakaandClaude Opus 4.8 6cbb225c9e gh-151886: Add tkinter Misc.tk_appname, tk_useinputmethods and tk_caret (GH-151887)
Wrap three long-standing Tk commands that had no tkinter wrapper:

* Misc.tk_appname() queries or sets the name used to communicate with the
  application through the send command (Tk 8.5).
* Misc.tk_useinputmethods() queries or sets whether Tk uses the X Input
  Methods (XIM) for filtering events (Tk 8.5).
* Misc.tk_caret() sets or queries the per-display caret location used for
  accessibility and for placing the input method window (Tk 8.5).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 17:31:25 +00:00
Serhiy StorchakaandClaude Opus 4.8 34eca5ac9d gh-151890: Support more photo image options in tkinter.PhotoImage methods (GH-151891)
Add parameters mapping to Tk photo image options that previously had no
tkinter equivalent:

* the format parameter of PhotoImage.put() (Tk 8.6),
* the metadata parameter of PhotoImage.put(), read(), write() and data()
  (Tk 9.0),
* the withalpha parameter of PhotoImage.get() (Tk 9.0).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 16:35:39 +00:00
Serhiy StorchakaandClaude Opus 4.8 b86c305c74 gh-151888: Add tkinter PhotoImage.redither method (GH-151889)
Wrap the photo image "redither" Tk command (since Tk 8.5) as the method
PhotoImage.redither(), which recalculates the dithered image in each
window where it is displayed (useful when the image data was supplied in
pieces), completing the wrapping of the photo image subcommands.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 15:19:56 +00:00
Serhiy StorchakaandClaude Opus 4.8 6185dfb450 gh-151881: Add tkinter Menu.postcascade, Misc.tk_scaling and tk_inactive (GH-151882)
Wrap three long-standing Tk commands that had no tkinter wrapper:

* Menu.postcascade() posts the submenu of a cascade entry (Tk 8.5),
  complementing the existing post() and unpost() methods.
* Misc.tk_scaling() queries or sets the scaling factor in pixels per
  point used to convert between physical units and pixels (Tk 8.4).
* Misc.tk_inactive() returns the user idle time in milliseconds, and can
  reset that timer (Tk 8.5).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 13:53:02 +00:00
Serhiy StorchakaandClaude Opus 4.8 b9bceb1fea gh-151876: Add tkinter Canvas methods rotate and rchars (GH-151877)
Wrap the Tk canvas commands "rchars" (replace the text or coordinates of
items, since Tk 8.6) and "rotate" (rotate the coordinates of items about
an origin, new in Tk 9.0) as the methods Canvas.rchars() and
Canvas.rotate(), complementing the existing dchars/insert and move/scale
methods.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 13:51:50 +00:00
Serhiy StorchakaandClaude Opus 4.8 13c1225443 gh-151910: Add tkinter.ttk.Treeview methods for the Tk 9.1 enhanced treeview (GH-151911)
Wrap the enhanced ttk::treeview widget commands added in Tk 9.1 (TIP 740),
and the detached query added in Tk 9.0, as tkinter.ttk.Treeview methods:
item navigation and queries (after_item, before_item, depth, haschildren,
visible, size, range, identifier, current), opening, hiding, sorting and
searching (expand, collapse, hide, unhide, sort, search, search_all,
search_cell, search_all_cells), cell focus, selection and tagging
(cellfocus, cellselection and its set/add/remove cell-list and *_range
rectangle forms, anchor/includes/present, tag_cell_add/remove/has), and the
detached query (detached, detached_all).

The expand() and collapse() methods, without recurse, also work on Tk older
than 9.1, where they are emulated via the item -open option.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 13:08:53 +00:00
Serhiy StorchakaandClaude Opus 4.8 c42f36ac53 gh-151878: Add tkinter Entry and Spinbox validate methods (GH-151879)
Wrap the Tk "validate" widget command of the entry and spinbox widgets as
the methods Entry.validate() and Spinbox.validate(), forcing an evaluation
of the validatecommand independently of the validate option and returning
whether the value is valid.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 12:52:50 +00:00
Serhiy StorchakaandClaude Opus 4.8 4de5683f21 gh-86726: Document tkinter method-name conflicts (GH-151917)
Document where widget methods shadow inherited Misc, geometry-manager and
Wm methods, correct the inaccurate "size/bbox is an alias of
grid_size/grid_bbox" claims, and add "# overrides X" comments at the
definitions.

Also document the geometry-manager ambiguity: the short names forget, info,
slaves, content and propagate are defined by Pack, Place and Grid but
resolve to the pack variant.

Cross-reference the window-manager methods grid, forget and state with the
same-named grid geometry manager, Pack.forget and ttk.Widget.state.


Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 12:14:10 +00:00
Serhiy StorchakaandClaude Opus 4.8 851b779760 gh-151874: Add tkinter wm_stackorder, wm_iconbadge and winfo_isdark (GH-151875)
Wrap the Tk commands "wm stackorder" (toplevel stacking order, since
Tk 8.4), "wm iconbadge" (application icon badge, new in Tk 9.0) and
"winfo isdark" (dark mode detection, new in Tk 9.0) as the methods
Wm.wm_stackorder(), Wm.wm_iconbadge() and Misc.winfo_isdark(), with the
usual stackorder and iconbadge short aliases.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-22 12:13:50 +00:00
Serhiy Storchaka 88e5d8a7b7 gh-151675: Add tkinter Text.sync() and Text.pendingsync() (GH-151677)
Wrap the Tk text widget "sync" and "pendingsync" subcommands, which
control and report the synchronization of the displayed view with the
underlying text when line heights have not yet been computed.
2026-06-20 17:11:21 +03:00
Serhiy StorchakaandClaude Opus 4.8 aa5b164577 gh-151674: Add tkinter Text.edit_canundo() and Text.edit_canredo() (GH-151676)
Wrap the Tk text widget "edit canundo" and "edit canredo" subcommands,
which report whether the undo and redo stacks are non-empty.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-20 09:39:09 +03:00
Matthias KievernagelandSerhiy Storchaka f8ce51a522 gh-47655: Add support for user data and detail of Tk events to tkinter (GH-7142)
Expose the %d substitution as the tkinter.Event attributes:

* "detail" for Enter, Leave, FocusIn, FocusOut, and ConfigureRequest events
* "user_data" for virtual events

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-02-25 10:34:00 +02:00
Serhiy Storchaka 71cbffde61 gh-143754: Add Tkinter methods pack_content(), place_content() and grid_content() (GH-143845)
They use Tk commands with new name like "pack content instead of old
"pack slaves".
2026-01-20 09:16:36 +02:00
Serhiy Storchaka 813fc7a291 gh-143754: Modernize Tkinter docs (GH-143841)
Use more relevant terminology instead of "master"/"slave" widgets where possible.
2026-01-19 14:01:29 +02:00
Stephen MortonandBénédikt Tran 81bfcf1aae gh-127930: use explicit imports in tkinter.simpledialog (#127931)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-12-14 12:38:42 +02:00
R.C.M 3d14805947 gh-130693: Support more options for search in tkinter.Text (GH-130848)
* Add parameters nolinestop and strictlimits in the tkinter.Text.search() method.
* Add the tkinter.Text.search_all() method.
* Add more tests for tkinter.Text.search().
* stopindex is now only ignored if it is None.
2025-11-17 14:42:26 +00:00
Serhiy Storchaka 09b1f10ef7 gh-140481: Improve error message when trying to iterate a Tk widget, image or font (GH-140501) 2025-10-30 13:11:56 +02:00
872eafd2b0 gh-76007: Deprecate __version__ attribute (#138675)
Co-authored-by: AN Long <aisk@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-09-29 12:03:23 +03:00
Serhiy Storchaka 027cacb67c gh-126008: Improve docstrings for Tkinter cget and configure methods (GH-133303)
* Explain the behavior of Widget.configure() depending on arguments.
* Unify descriptions.
* Replace "resource" with "option".
2025-08-12 07:55:01 +03:00
Disconnect3d 69ea1b3a8f gh-136839: Refactor simple dict.update calls (#136811)
Refactor simple dict.update calls

This commit refactors simple `dict.update({key: value})` calls which can
be done via `dict[key] = value` instead.

I found those cases with the [semgrep](https://semgrep.dev/) tool:

```
$ semgrep --lang python --pattern '$DICT.update({$A: ...})'

┌─────────────────┐
│ 5 Code Findings │
└─────────────────┘

    Lib/dataclasses.py
         1268┆ slots.update({slot: doc})

    Lib/multiprocessing/resource_tracker.py
           50┆ _CLEANUP_FUNCS.update({
           51┆     'semaphore': _multiprocessing.sem_unlink,
           52┆ })
            ⋮┆----------------------------------------
           53┆ _CLEANUP_FUNCS.update({
           54┆     'shared_memory': _posixshmem.shm_unlink,
           55┆ })

    Lib/tkinter/scrolledtext.py
           26┆ kw.update({'yscrollcommand': self.vbar.set})

    Lib/xmlrpc/server.py
          242┆ self.funcs.update({'system.multicall' : self.system_multicall})
```
2025-07-19 10:12:10 -07:00
Zhikang Yan e490c00dac gh-130482: Add ability to specify name for tkinter.OptionMenu and tkinter.ttk.OptionMenu (GH-130502) 2025-05-02 14:38:50 +03:00
Serhiy Storchaka c46635aa5a gh-120220: Deprecate legacy methods for tracing variables in Tkinter (GH-120223)
They do not work with Tcl 9.0.
Use new methods added in Python 3.6.
2025-04-29 20:26:51 +03:00