Skip to content

gh-59396: Modernize tkinter.simpledialog#151848

Open
serhiy-storchaka wants to merge 5 commits into
python:mainfrom
serhiy-storchaka:tkinter-simpledialog
Open

gh-59396: Modernize tkinter.simpledialog#151848
serhiy-storchaka wants to merge 5 commits into
python:mainfrom
serhiy-storchaka:tkinter-simpledialog

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Jun 21, 2026

Copy link
Copy Markdown
Member

This reworks tkinter.simpledialog to match the look and feel of the native Tk dialogs: SimpleDialog is a port of ::tk_dialog, and Dialog is a base class whose button box is modelled on ::tk::MessageBox.

  • SimpleDialog, askinteger, askfloat and askstring now use the themed tkinter.ttk widgets by default; the Dialog base class still defaults to the classic widgets for compatibility. Both classes gained a keyword-only use_ttk parameter to select the widget set.
  • Both dialogs follow the message-box keyboard conventions: button accelerators (Alt + the underlined letter), a default ring that follows the keyboard focus, and <Return> that invokes the focused button.
  • SimpleDialog gained bitmap and detail parameters, draws the standard icons with themed images in the ttk version, and accepts mappings of button options as buttons entries.
  • The message and detail font and wrap length are taken from the Tk option database and can be overridden by the application.
  • The new helpers _temp_grab_focus, _underline_ampersand and _find_alt_key_target can be reused by other tkinter dialogs, as _setup_dialog already is.
  • Several bugs found by comparison with the Tcl sources were fixed.

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.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@read-the-docs-community

read-the-docs-community Bot commented Jun 21, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #33237157 | 📁 Comparing 2a0ad97 against main (082ac30)

  🔍 Preview build  

3 files changed
± library/dialog.html
± whatsnew/3.16.html
± whatsnew/changelog.html

serhiy-storchaka and others added 3 commits June 21, 2026 19:28
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
# Conflicts:
#	Doc/library/dialog.rst
#	Lib/test/test_tkinter/test_simpledialog.py
Add a button per dialog, a checkbox to toggle classic/themed widgets, and
show a bitmap, a detail message and Alt-key button accelerators in the
SimpleDialog example.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant