Commit graph

554 commits

Author SHA1 Message Date
Serhiy Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Storchaka
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 Kievernagel
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 Morton
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
Hugo van Kemenade
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
Zhikang Yan
da8825ea95
gh-128562: Fix generation of the tkinter widget names (GH-128604)
There were possible conflicts if the widget class name ends with a digit.
2025-01-13 15:54:46 +00:00
Zhikang Yan
58e9f95c4a
gh-128014: Fix passing default='' to the tkinter method wm_iconbitmap() (GH-128015)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2025-01-02 17:51:57 +02:00
Zhikang Yan
7ea523f47c
gh-126899: Add **kw to tkinter.Misc.after and tkinter.Misc.after_idle (#126900)
---------
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2024-12-01 19:29:27 +00:00
Marc Culler
47cbf03885
gh-124111: Update tkinter for compatibility with Tcl/Tk 9.0.0 (GH-124156) 2024-11-14 12:45:08 -06:00
Yoda
42a818912b
gh-123341: Support tkinter.Event type subcript (#123353)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2024-09-01 12:47:07 +01:00
Wulian
94036e43a8
Fix typos in comments (#123201) 2024-08-21 12:49:23 +00:00
Serhiy Storchaka
1a0c7b9ba4
gh-121905: Consistently use "floating-point" instead of "floating point" (GH-121907) 2024-07-19 08:06:02 +00:00
Serhiy Storchaka
d68a22e7a6
gh-120211: Fix tkinter.ttk with Tcl/Tk 9.0 (GH-120213)
* Use new methods for tracing Tcl variable.
* Fix Combobox.current() for empty combobox.
2024-06-07 10:49:07 +00:00
Serhiy Storchaka
e188527c34
gh-118760: Restore the default value of tkinter.wantobjects to 1 (GH-118784)
It was set to 2 in 65f5e586a1 (GH-98592).
2024-05-20 22:21:04 +03:00
Serhiy Storchaka
5b88d95cc5
gh-118760: Fix errors in calling Tkinter bindings on Windows (GH-118782)
For unknown reasons some arguments for Tkinter binding can be created
as a 1-tuple containing a Tcl_Obj when wantobjects is 2.
2024-05-15 19:49:00 +03:00
Serhiy Storchaka
65f5e586a1
gh-66410: Do not stringify arguments of Tkinter callback (GH-98592)
Callbacks registered in the tkinter module now take arguments as
various Python objects (int, float, bytes, tuple), not just str.
To restore the previous behavior set tkinter module global wantobject to 1
before creating the Tk object or call the wantobject() method of the Tk object
with argument 1.
Calling it with argument 2 restores the current default behavior.
2024-05-07 12:07:32 +00:00
Serhiy Storchaka
1ff626ebda
gh-71592: Add ability to trace Tcl commands executed by Tkinter (GH-118291)
This is an experimental feature, for internal use.

Setting tkinter._debug = True before creating the root window enables
printing every executed Tcl command (or a Tcl command equivalent to the
used Tcl C API).

This will help to convert a Tkinter example into Tcl script to check
whether the issue is caused by Tkinter or exists in the underlying Tcl/Tk
library.
2024-05-06 20:12:51 +03:00
Serhiy Storchaka
709ca90a00
gh-118271: Support more options for reading/writing images in Tkinter (GH-118273)
* Add PhotoImage.read() to read an image from a file.
* Add PhotoImage.data() to get the image data.
* Add background and grayscale parameters to PhotoImage.write().
2024-05-06 15:06:06 +00:00
Serhiy Storchaka
1b639a04ca
gh-118225: Support more options for copying images in Tkinter (GH-118228)
* Add the PhotoImage method copy_replace() to copy a region
  from one image to other image, possibly with pixel zooming and/or
  subsampling.
* Add from_coords parameter to PhotoImage methods copy(), zoom() and subsample().
* Add zoom and subsample parameters to PhotoImage method copy().
2024-05-06 17:33:15 +03:00
Cheryl Sabella
194fd17bc6
bpo-32839: Add the after_info() method for Tkinter widgets (GH-5664) 2024-04-27 00:27:58 +03:00
Serhiy Storchaka
c61cb507c1
gh-116484: Fix collisions between Checkbutton and ttk.Checkbutton default names (GH-116495)
Change automatically generated tkinter.Checkbutton widget names to
avoid collisions with automatically generated tkinter.ttk.Checkbutton
widget names within the same parent widget.
2024-03-16 13:31:19 +02:00
Serhiy Storchaka
d2c4baa41f
gh-97928: Partially restore the behavior of tkinter.Text.count() by default (GH-115031)
By default, it preserves an inconsistent behavior of older Python
versions: packs the count into a 1-tuple if only one or none
options are specified (including 'update'), returns None instead of 0.
Except that setting wantobjects to 0 no longer affects the result.

Add a new parameter return_ints: specifying return_ints=True makes
Text.count() always returning the single count as an integer
instead of a 1-tuple or None.
2024-02-11 12:43:14 +02:00
Serhiy Storchaka
b4ba0f73d6
gh-43457: Tkinter: fix design flaws in wm_attributes() (GH-111404)
* When called with a single argument to get a value, it allow to omit
  the minus prefix.
* It can be called with keyword arguments to set attributes.
* w.wm_attributes(return_python_dict=True) returns a dict instead of 
  a tuple (it will be the default in future).
* Setting wantobjects to 0 no longer affects the result.
2024-02-05 18:24:54 +02:00
Serhiy Storchaka
7e42fddf60
gh-113951: Tkinter: "tag_unbind(tag, sequence, funcid)" now only unbinds "funcid" (GH-113955)
Previously, "tag_unbind(tag, sequence, funcid)" methods of Text and
Canvas widgets destroyed the current binding for "sequence", leaving
"sequence" unbound, and deleted the "funcid" command.

Now they remove only "funcid" from the binding for "sequence", keeping
other commands, and delete the "funcid" command.
They leave "sequence" unbound only if "funcid" was the last bound command.
2024-02-04 17:49:42 +02:00
Christopher Chavez
b8f29b1293
gh-110345: show Tcl/Tk patchlevel in tkinter._test() (GH-110350) 2024-01-18 17:46:58 +02:00