Skip to content

Some tkinter query methods return int or a raw value instead of bool #153422

Description

@serhiy-storchaka

Feature or enhancement

A few tkinter query methods with a boolean result return int or a raw Tcl value instead of bool:

  • Misc.winfo_exists(), Misc.winfo_ismapped() and Misc.winfo_viewable() return int (they use getint()).
  • Text.edit_modified() returns the raw result of edit modified, so its type depends on wantobjects: int when it is on, str ('0'/'1') when it is off.

All the other boolean-valued query methods already return a proper bool: Misc.winfo_colormapfull(), winfo_isdark(), tk_busy_status(), wm_overrideredirect(), wm_stackorder(isabove/isbelow), Text.compare(), edit_canundo(), edit_canredo(), pendingsync(), the selection_present()/selection_includes()/validate() methods of Entry, Listbox and Spinbox, PhotoImage.transparency_get(), ttk.Widget.instate(), and the ttk.Treeview predicates (haschildren(), visible(), detached(), cellselection_includes(), cellselection_present(), tag_cell_has()).

I propose to make the four outliers consistent:

  • the three winfo_* methods use getboolean() instead of getint();
  • edit_modified() coerces the query result with getboolean() (the setter form, with an argument, is unchanged).

bool is a subclass of int, so existing boolean and arithmetic uses keep working; only code relying on the exact int/str type of the result is affected.

The winfo_* methods have coerced the result to int since the initial revision of tkinter, predating the bool type (added in Python 2.3) -- at the time there was no boolean type to return, and the choice was never revisited when bool was introduced.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-tkintertype-featureA feature request or enhancement

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions