Pieter Eendebak [Wed, 24 Jun 2026 11:09:50 +0000 (13:09 +0200)]
gh-152056: Compile single-category character sets to a bare CATEGORY opcode (GH-152057)
A character set containing exactly one category, e.g. [\d] or [^\s], now
compiles to a single CATEGORY opcode (like \d or \S) instead of an IN
block. The negated form maps to the complementary category. This speeds
up matching and reduces the size of the compiled byte code.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Wed, 24 Jun 2026 06:30:17 +0000 (09:30 +0300)]
gh-84008: Document that the LC_NUMERIC locale affects tkinter numeric widgets (GH-152008)
Spinbox, Scale and ttk.Spinbox format floating-point values according to
the LC_NUMERIC locale, but such values are always parsed with a period, so
a comma-decimal locale breaks DoubleVar.get().
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Wed, 24 Jun 2026 06:08:34 +0000 (09:08 +0300)]
gh-87904: Document curses classes (GH-151643)
Add docstrings for the curses.window, curses.error, curses.panel.panel
and curses.panel.error classes. Document the panel class and its error
exception in curses.panel.rst, using the real lowercase panel name.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Wed, 24 Jun 2026 05:52:10 +0000 (08:52 +0300)]
gh-151757: Support wide and combining characters in the curses module (GH-151758)
The character-cell window methods now accept a full character cell -- a
spacing character optionally followed by combining characters (up to
CCHARW_MAX wide characters) -- in addition to a single int or byte
character. This affects addch(), bkgd(), bkgdset(), border(), box(),
echochar(), hline(), insch() and vline(); they dispatch to the ncursesw
wide-character functions (wadd_wch(), wbkgrnd(), wborder_set(),
wecho_wchar(), whline_set(), wins_wch(), wvline_set(), ...) when given a
string. border() and box() cannot mix integer or byte characters with
wide string characters in a single call. A cell is one spacing character
optionally followed by combining characters, so an extra spacing or
control character (such as "ab") is rejected with ValueError rather than
being silently truncated by setcchar().
Also add the wide-character read methods get_wstr() and in_wstr(), the
counterparts of getstr() and instr() that return a str rather than a
bytes object, and the module functions erasewchar(), killwchar() and
wunctrl(), the wide-character counterparts of erasechar(), killchar()
and unctrl().
All of this is available only when built against the wide-character
ncursesw library.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Wed, 24 Jun 2026 05:49:14 +0000 (08:49 +0300)]
gh-152033: Optimize category escapes outside character sets (GH-152035)
Character class escapes (``\d``, ``\D``, ``\s``, ``\S``, ``\w`` and
``\W``) that occur outside a character set are now compiled directly to a
single CATEGORY opcode instead of being wrapped in an IN block. This
removes the IN wrapper (three code words) and an indirect charset() call,
and makes such an escape a simple repeatable unit so that, for example,
``\d+`` uses the REPEAT_ONE fast path; a CATEGORY case is added to
SRE(count).
The transformation preserves behaviour exactly. For category-heavy
patterns the compiled byte code is about 20% smaller and matching is up
to ~2x faster, with no effect on patterns that do not use bare category
escapes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The size is taken from the archive and is not validated, so a ~512-byte
crafted file can claim several gigabytes (or, via base-256 encoding, far
more) and make read() pre-allocate that much memory -- on open/iterate,
before any extraction filter runs.
Read the extended-header data in bounded chunks instead, so an oversized
or truncated header can no longer force a huge allocation. The bytes
returned for valid archives are unchanged.
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>
Serhiy Storchaka [Tue, 23 Jun 2026 06:24:17 +0000 (09:24 +0300)]
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>
Serhiy Storchaka [Mon, 22 Jun 2026 17:43:43 +0000 (20:43 +0300)]
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>
Serhiy Storchaka [Mon, 22 Jun 2026 17:31:25 +0000 (20:31 +0300)]
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>
Serhiy Storchaka [Mon, 22 Jun 2026 16:35:39 +0000 (19:35 +0300)]
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>
Fixes issue #150162 by improving the code introduced by 70154855cf69
(GH-127729) while retaining the original documented intent. The
aforementioned code has a side effect when used in a virtual environment
context, on posix platforms, with the cross-compiling environment
variable _PYTHON_PROJECT_BASE present. In this case, every single
sysconfig.get_config_vars() and sysconfig.get_config_var() call, forces
the _CONFIG_VARS dictionary to be reinitialised from scratch. This is
inefficient, but also means no changes to the dictionary returned by
sysconfig.get_config_vars() persist, which can be useful in certain
situations.
This commit tracks changes to sys.prefix and sys.exec_prefix more
directly rather than relying on a misalignment with the corresponding
sysconfig variables.
Bernát Gábor [Mon, 22 Jun 2026 15:39:08 +0000 (08:39 -0700)]
gh-140006: Harden fish prompt against shadowed builtins (#150936)
A user function that shadows the `.`/`source` builtin hijacks the
activate.fish prompt. fish resolves functions ahead of builtins, so the
`echo "exit $status" | .` line that restores the exit status pipes into
the user function instead of sourcing. Dot-style directory navigators
redefine `.`, which made the prompt list the directory on every command
and dropped the exit status handed to the original prompt.
Route every builtin the prompt path uses (`source`, `echo`, `printf`,
`set_color`, `functions`) through `builtin` so no user function can
intercept them. These have all been fish builtins with a stable
interface since fish 2.0.0, the version the script already required
through `functions --copy`, so the minimum supported fish version does
not change.
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>
Ronan Pigott [Mon, 22 Jun 2026 14:40:23 +0000 (07:40 -0700)]
gh-111501: venv: do not export PS1 in activate (#105279)
PS1 is a parameter special to the current interactive shell. It does not
need to be exported to the environment. Exporting PS1 is not useful, and
will break different shells spawned by the current interactive shell.
_andthereitgoes [Mon, 22 Jun 2026 14:07:39 +0000 (00:07 +1000)]
Correct typos in `runpy.run_path` documentation (#151230)
*file_path* -> *path_name* in runpy.rst
The documentation for runpy.run_path refers to a parameter called *file_path*, which doesn't exist in the call spec. However, *path_name* exists, and it is implied that *file_path* actually refers to *path_name*.
Serhiy Storchaka [Mon, 22 Jun 2026 13:53:02 +0000 (16:53 +0300)]
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>
Serhiy Storchaka [Mon, 22 Jun 2026 13:51:50 +0000 (16:51 +0300)]
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>
Serhiy Storchaka [Mon, 22 Jun 2026 12:52:50 +0000 (15:52 +0300)]
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>
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>
Serhiy Storchaka [Mon, 22 Jun 2026 12:13:50 +0000 (15:13 +0300)]
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>
The test forced a rollover by back-dating the file modification time, but
the rollover time is now based also on the creation time, which cannot be
changed. Instead, set the rollover time one second after the file
creation time and wait until the clock reaches it.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Sat, 20 Jun 2026 14:31:40 +0000 (17:31 +0300)]
gh-151678: Add tests for tkinter widget virtual events (GH-151793)
Verify the virtual events that widgets emit in response to user
interaction, driven by generated events: <<ListboxSelect>> (Listbox),
<<Increment>> and <<Decrement>> (ttk Spinbox), and <<TreeviewSelect>>,
<<TreeviewOpen>> and <<TreeviewClose>> (ttk Treeview).
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Sat, 20 Jun 2026 14:11:21 +0000 (17:11 +0300)]
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.
Serhiy Storchaka [Sat, 20 Jun 2026 13:46:39 +0000 (16:46 +0300)]
gh-151678: Add interactive tests for tkinter.simpledialog (GH-151794)
Drive the modal query dialogs with generated events to exercise the
<Return> and <Escape> key bindings and the value validation: accepting
an integer, float or string, cancelling, rejecting a non-numeric value
and rejecting a value outside the allowed range.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Sat, 20 Jun 2026 13:42:53 +0000 (16:42 +0300)]
gh-151678: Add tests for the remaining tkinter Misc, Wm and Text methods (GH-151782)
Cover Misc.wait_variable and wait_window, tk_focusFollowsMouse,
selection_handle, the error paths of grab_set_global, send, the
X11-specific Wm methods iconposition, iconmask, iconwindow,
colormapwindows and manage/forget, and the Text.window_config alias and
deprecated yview_pickplace.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Sat, 20 Jun 2026 13:21:19 +0000 (16:21 +0300)]
gh-151678: Add tests for tkinter.filedialog (GH-151781)
Exercise the native dialogs (Open, SaveAs and Directory) through the
_test_callback seam without opening them, and test the pure-Python
FileDialog selection, filter and ok/cancel logic without entering its
modal loop.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Serhiy Storchaka [Fri, 19 Jun 2026 23:39:34 +0000 (02:39 +0300)]
gh-151678: Add tests for tkinter.scrolledtext (GH-151753)
Add a test for the ScrolledText widget, which had no tests: that it is
a Text widget held in a Frame with a Scrollbar, that Text methods work,
that the geometry manager methods are redirected to the frame while
configure is not, and that the scrollbar tracks the text view.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Fri, 19 Jun 2026 22:45:47 +0000 (01:45 +0300)]
gh-151678: Add tests for tkinter font, image, variable, Misc and Wm methods (GH-151751)
* font: copy(), the config alias, the displayof argument of measure and
metrics, and the errors raised for invalid options and a wrong number
of arguments;
* image: the cget method and the config alias, and the errors raised by
transparency_get and transparency_set;
* variable: that initialize is an alias of set and the deprecated trace
is an alias of trace_variable;
* Misc: tk_focusNext, tk_focusPrev, tk_strictMotif, tk_bisque and
option_readfile;
* Wm: wm_iconphoto.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Fri, 19 Jun 2026 17:49:26 +0000 (20:49 +0300)]
gh-151744: Add curses.nofilter() (GH-151747)
Wrap the ncurses nofilter() function, which undoes the effect of
filter(). Without it there is no way to restore normal screen sizing
after a curses.filter() call in the same process.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Fri, 19 Jun 2026 14:38:32 +0000 (17:38 +0300)]
gh-151678: Add tests for tkinter Misc, Wm and geometry manager methods (GH-151732)
Cover previously-untested methods of the Misc, Wm, Pack, Place and Grid
classes:
* a new WinfoTest class for the winfo_* query methods (class, name,
parent, children, toplevel, visual and screen information, atoms,
pointer and screen coordinates, fpixels, containing, interps,
viewable), including the pre-existing winfo_rgb and winfo_pathname;
* in MiscTest: getint, getdouble, getvar, register, deletecommand,
option_add/get/clear, nametowidget, the focus_*, grab_* and
selection_own* methods, event_add/delete/info, and bell;
* in WmTest: title, geometry, minsize/maxsize, resizable, aspect, grid,
positionfrom/sizefrom, focusmodel, iconname, client/command,
overrideredirect, state (with withdraw and deiconify), frame, group,
protocol and transient;
* the short-named aliases of the grid_*, pack_* and place_* geometry
manager methods.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gh-150836: Mount embedded Tk ZIP in _tkinter on Windows (GH-151562)
Tcl/Tk 9 may embed the Tk script library in the Tk DLL on Windows. This embedded library is not found by Tcl by default.
Mount the loaded Tk DLL as a zipfs archive before calling Tk_Init(), so Tk can find its embedded tk_library using its existing library discovery logic.
Preserve Tk_Init()'s normal path if the library is not embedded.
Serhiy Storchaka [Fri, 19 Jun 2026 10:23:38 +0000 (13:23 +0300)]
gh-151678: Add tests for the remaining tkinter widgets (GH-151687)
Cover previously-untested methods of several widgets:
* Button, Checkbutton and Radiobutton: invoke, flash and toggle;
* Entry: delete, icursor and the select_* aliases;
* Spinbox: invoke, identify and scan;
* Scale and Scrollbar: identify, and Scrollbar fraction and delta;
* PanedWindow: panes, remove/forget, sash and proxy positioning,
identify, and adding panes with configuration options.
Also test that invoke does nothing for a disabled button and the
errors raised for invalid indices, coordinates, option names and values.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Fri, 19 Jun 2026 09:13:41 +0000 (12:13 +0300)]
gh-151678: Add tests for tkinter.Canvas (GH-151683)
Cover previously-untested Canvas methods in CanvasTest:
* item creation and types, bbox, coordinate conversion, move/scale,
find and addtag queries, tags, item configuration, stacking order,
text-item editing, selection, focus, scan and postscript;
* the create_arc, create_oval, create_bitmap, create_image,
create_text and create_window item creation methods, checking
coordinates, default and explicit options, valid enumerations and
rejection of invalid values;
* tag_bind() and tag_unbind(), checking the returned function id and
binding script, querying bound sequences, the add parameter, event
delivery to items via a tag, and removal of a single binding by id
or all bindings for a sequence.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Fri, 19 Jun 2026 09:04:10 +0000 (12:04 +0300)]
gh-151678: Add tests for tkinter.Listbox (GH-151686)
Cover previously-untested Listbox methods in ListboxTest: size, delete,
index resolution, nearest, see, activate, and the selection methods
(selection_set/clear/includes/anchor and their select_* aliases),
including the errors raised for invalid indices.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Fri, 19 Jun 2026 08:59:14 +0000 (11:59 +0300)]
gh-151678: Add tests for tkinter.Menu (GH-151685)
Cover previously-untested Menu methods in MenuTest: adding, inserting and
deleting items of every type, index resolution, invoking items, entry x/y
positions, and post/unpost/tk_popup mapping.
Also test per-entry configuration options and the errors raised for
invalid indices, entry types, option names and option values.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Fri, 19 Jun 2026 08:38:15 +0000 (11:38 +0300)]
gh-151695: Fix use-after-free of the curses screen encoding (GH-151696)
The module-global curses_screen_encoding stored a borrowed pointer to the
encoding owned by the window returned by the first initscr() call. That
window can be deallocated while unctrl() and ungetch(), which have no window
of their own, still use the pointer to encode non-ASCII characters.
Keep a private copy of the encoding instead.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Serhiy Storchaka [Fri, 19 Jun 2026 08:38:02 +0000 (11:38 +0300)]
gh-151678: Add tests for tkinter.Text (GH-151681)
Cover previously-untested Text methods (indices, content, marks, tags,
undo/redo, dump, embedded images and windows, peers, and geometry) and
the tag, embedded-image and embedded-window configuration options.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
da-woods [Thu, 18 Jun 2026 12:53:09 +0000 (13:53 +0100)]
gh-141510 Document and test frozendict class matching behaviour (#150799)
Frozendict has `_Py_TPFLAGS_MATCH_SELF` set so works correctly
with the single-arg class matching. However it isn't documented
in the list of classes this works with and it isn't tested.
The test is some way below the other similar tests but anything
else would need a large renumbering.
Serhiy Storchaka [Thu, 18 Jun 2026 12:39:06 +0000 (15:39 +0300)]
gh-86726: Document the full public API of tkinter (GH-151579)
Replace the previously sparse reference documentation with full coverage of
the public API of the tkinter package, written from the Tcl/Tk manual pages,
the existing documentation and the module docstrings.
* Doc/library/tkinter.rst gains a "Reference" section documenting every public
class, method, function and constant of the core module -- the widgets, the
Misc, Wm, Pack, Place, Grid, XView and YView mix-ins, the Variable and image
classes, the module-level functions and the symbolic constants.
* Doc/library/tkinter.ttk.rst, dialog.rst, tkinter.font.rst and the other
module pages document their remaining classes, methods and functions.
The descriptions are Python-oriented (correct return types -- tuples rather
than Tcl lists, booleans, integers, None on cancellation, and so on) and were
checked against the Tcl/Tk 9.1 manual pages and the implementation.
versionadded, versionchanged and deprecated directives are added for the
public API, determined from the git history relative to Python 3.0: the
tkinter.ttk module (3.1); the Text, Wm, Menu and Misc methods exposing Tk 8.5
features (3.3); and the many later additions and behavior changes up to 3.15.
The Tk version required by features added after Tk 8.6 is noted as well. The
bundled Tcl/Tk version is updated to 9.0 and the manual-page links point at
the tcl9.0 reference.
--------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>