Use PEP 585 syntax wherever possible (#6717)

This commit is contained in:
Alex Waygood
2021-12-28 10:31:43 +00:00
committed by GitHub
parent e6cb341d94
commit 8d5d2520ac
237 changed files with 966 additions and 1069 deletions

View File

@@ -5,7 +5,7 @@ from enum import Enum
from tkinter.constants import *
from tkinter.font import _FontDescription
from types import TracebackType
from typing import Any, Callable, Generic, List, Mapping, Optional, Protocol, Sequence, Tuple, Type, TypeVar, Union, overload
from typing import Any, Callable, Generic, Mapping, Optional, Protocol, Sequence, Type, TypeVar, Union, overload
from typing_extensions import Literal, TypedDict
# Using anything from tkinter.font in this file means that 'import tkinter'
@@ -42,18 +42,18 @@ _ButtonCommand = Union[str, Callable[[], Any]] # accepts string of tcl code, re
_CanvasItemId = int
_Color = str # typically '#rrggbb', '#rgb' or color names.
_Compound = Literal["top", "left", "center", "right", "bottom", "none"] # -compound in manual page named 'options'
_Cursor = Union[str, Tuple[str], Tuple[str, str], Tuple[str, str, str], Tuple[str, str, str, str]] # manual page: Tk_GetCursor
_Cursor = Union[str, tuple[str], tuple[str, str], tuple[str, str, str], tuple[str, str, str, str]] # manual page: Tk_GetCursor
_EntryValidateCommand = Union[
Callable[[], bool], str, List[str], Tuple[str, ...]
Callable[[], bool], str, list[str], tuple[str, ...]
] # example when it's sequence: entry['invalidcommand'] = [entry.register(print), '%P']
_GridIndex = Union[int, str, Literal["all"]]
_ImageSpec = Union[_Image, str] # str can be from e.g. tkinter.image_names()
_Padding = Union[
_ScreenUnits,
Tuple[_ScreenUnits],
Tuple[_ScreenUnits, _ScreenUnits],
Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits],
Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _ScreenUnits],
tuple[_ScreenUnits],
tuple[_ScreenUnits, _ScreenUnits],
tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits],
tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _ScreenUnits],
]
_Relief = Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] # manual page: Tk_GetRelief
_ScreenUnits = Union[str, float] # Often the right type instead of int. Manual page: Tk_GetPixels
@@ -137,7 +137,7 @@ class Variable:
def get(self) -> Any: ...
def trace_add(self, mode: _TraceMode, callback: Callable[[str, str, str], Any]) -> str: ...
def trace_remove(self, mode: _TraceMode, cbname: str) -> None: ...
def trace_info(self) -> list[tuple[Tuple[_TraceMode, ...], str]]: ...
def trace_info(self) -> list[tuple[tuple[_TraceMode, ...], str]]: ...
def trace_variable(self, mode, callback): ... # deprecated
def trace_vdelete(self, mode, cbname): ... # deprecated
def trace_vinfo(self): ... # deprecated
@@ -249,7 +249,7 @@ class Misc:
def winfo_geometry(self) -> str: ...
def winfo_height(self) -> int: ...
def winfo_id(self) -> int: ...
def winfo_interps(self, displayof: Literal[0] | Misc | None = ...) -> Tuple[str, ...]: ...
def winfo_interps(self, displayof: Literal[0] | Misc | None = ...) -> tuple[str, ...]: ...
def winfo_ismapped(self) -> bool: ...
def winfo_manager(self) -> str: ...
def winfo_name(self) -> str: ...
@@ -420,9 +420,9 @@ class Misc:
x: _ScreenUnits = ...,
y: _ScreenUnits = ...,
) -> None: ...
def event_info(self, virtual: str | None = ...) -> Tuple[str, ...]: ...
def image_names(self) -> Tuple[str, ...]: ...
def image_types(self) -> Tuple[str, ...]: ...
def event_info(self, virtual: str | None = ...) -> tuple[str, ...]: ...
def image_names(self) -> tuple[str, ...]: ...
def image_types(self) -> tuple[str, ...]: ...
# See #4363 and #4891
def __setitem__(self, key: str, value: Any) -> None: ...
def __getitem__(self, key: str) -> Any: ...
@@ -468,7 +468,7 @@ class Wm:
) -> tuple[int, int, int, int] | None: ...
aspect = wm_aspect
@overload
def wm_attributes(self) -> Tuple[Any, ...]: ...
def wm_attributes(self) -> tuple[Any, ...]: ...
@overload
def wm_attributes(self, __option: str) -> Any: ...
@overload
@@ -479,7 +479,7 @@ class Wm:
@overload
def wm_colormapwindows(self) -> list[Misc]: ...
@overload
def wm_colormapwindows(self, __wlist: list[Misc] | Tuple[Misc, ...]) -> None: ...
def wm_colormapwindows(self, __wlist: list[Misc] | tuple[Misc, ...]) -> None: ...
@overload
def wm_colormapwindows(self, __first_wlist_item: Misc, *other_wlist_items: Misc) -> None: ...
colormapwindows = wm_colormapwindows
@@ -543,7 +543,7 @@ class Wm:
@overload
def wm_protocol(self, name: str, func: None = ...) -> str: ...
@overload
def wm_protocol(self, name: None = ..., func: None = ...) -> Tuple[str, ...]: ...
def wm_protocol(self, name: None = ..., func: None = ...) -> tuple[str, ...]: ...
protocol = wm_protocol
@overload
def wm_resizable(self, width: None = ..., height: None = ...) -> tuple[bool, bool]: ...
@@ -1043,17 +1043,17 @@ class Canvas(Widget, XView, YView):
def addtag_overlapping(self, newtag: str, x1: _ScreenUnits, y1: _ScreenUnits, x2: _ScreenUnits, y2: _ScreenUnits) -> None: ...
def addtag_withtag(self, newtag: str, tagOrId: str | _CanvasItemId) -> None: ...
def find(self, *args): ... # internal method
def find_above(self, tagOrId: str | _CanvasItemId) -> Tuple[_CanvasItemId, ...]: ...
def find_all(self) -> Tuple[_CanvasItemId, ...]: ...
def find_below(self, tagOrId: str | _CanvasItemId) -> Tuple[_CanvasItemId, ...]: ...
def find_above(self, tagOrId: str | _CanvasItemId) -> tuple[_CanvasItemId, ...]: ...
def find_all(self) -> tuple[_CanvasItemId, ...]: ...
def find_below(self, tagOrId: str | _CanvasItemId) -> tuple[_CanvasItemId, ...]: ...
def find_closest(
self, x: _ScreenUnits, y: _ScreenUnits, halo: _ScreenUnits | None = ..., start: str | _CanvasItemId | None = ...
) -> Tuple[_CanvasItemId, ...]: ...
) -> tuple[_CanvasItemId, ...]: ...
def find_enclosed(
self, x1: _ScreenUnits, y1: _ScreenUnits, x2: _ScreenUnits, y2: _ScreenUnits
) -> Tuple[_CanvasItemId, ...]: ...
def find_overlapping(self, x1: _ScreenUnits, y1: _ScreenUnits, x2: _ScreenUnits, y2: float) -> Tuple[_CanvasItemId, ...]: ...
def find_withtag(self, tagOrId: str | _CanvasItemId) -> Tuple[_CanvasItemId, ...]: ...
) -> tuple[_CanvasItemId, ...]: ...
def find_overlapping(self, x1: _ScreenUnits, y1: _ScreenUnits, x2: _ScreenUnits, y2: float) -> tuple[_CanvasItemId, ...]: ...
def find_withtag(self, tagOrId: str | _CanvasItemId) -> tuple[_CanvasItemId, ...]: ...
# Incompatible with Misc.bbox(), tkinter violates LSP
def bbox(self, *args: str | _CanvasItemId) -> tuple[int, int, int, int]: ... # type: ignore[override]
@overload
@@ -1076,7 +1076,7 @@ class Canvas(Widget, XView, YView):
@overload
def coords(self) -> list[float]: ...
@overload
def coords(self, __args: list[int] | list[float] | Tuple[float, ...]) -> None: ...
def coords(self, __args: list[int] | list[float] | tuple[float, ...]) -> None: ...
@overload
def coords(self, __x1: float, __y1: float, *args: float) -> None: ...
# create_foo() methods accept coords as a list, a tuple, or as separate arguments.
@@ -1092,16 +1092,16 @@ class Canvas(Widget, XView, YView):
__x1: float,
__y1: float,
*,
activedash: str | list[int] | Tuple[int, ...] = ...,
activedash: str | list[int] | tuple[int, ...] = ...,
activefill: _Color = ...,
activestipple: str = ...,
activewidth: _ScreenUnits = ...,
arrow: Literal["first", "last", "both"] = ...,
arrowshape: tuple[float, float, float] = ...,
capstyle: Literal["round", "projecting", "butt"] = ...,
dash: str | list[int] | Tuple[int, ...] = ...,
dash: str | list[int] | tuple[int, ...] = ...,
dashoffset: _ScreenUnits = ...,
disableddash: str | list[int] | Tuple[int, ...] = ...,
disableddash: str | list[int] | tuple[int, ...] = ...,
disabledfill: _Color = ...,
disabledstipple: _Bitmap = ...,
disabledwidth: _ScreenUnits = ...,
@@ -1112,7 +1112,7 @@ class Canvas(Widget, XView, YView):
splinesteps: float = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@overload
@@ -1120,16 +1120,16 @@ class Canvas(Widget, XView, YView):
self,
__coords: tuple[float, float, float, float] | list[int] | list[float],
*,
activedash: str | list[int] | Tuple[int, ...] = ...,
activedash: str | list[int] | tuple[int, ...] = ...,
activefill: _Color = ...,
activestipple: str = ...,
activewidth: _ScreenUnits = ...,
arrow: Literal["first", "last", "both"] = ...,
arrowshape: tuple[float, float, float] = ...,
capstyle: Literal["round", "projecting", "butt"] = ...,
dash: str | list[int] | Tuple[int, ...] = ...,
dash: str | list[int] | tuple[int, ...] = ...,
dashoffset: _ScreenUnits = ...,
disableddash: str | list[int] | Tuple[int, ...] = ...,
disableddash: str | list[int] | tuple[int, ...] = ...,
disabledfill: _Color = ...,
disabledstipple: _Bitmap = ...,
disabledwidth: _ScreenUnits = ...,
@@ -1140,7 +1140,7 @@ class Canvas(Widget, XView, YView):
splinesteps: float = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@overload
@@ -1151,15 +1151,15 @@ class Canvas(Widget, XView, YView):
__x1: float,
__y1: float,
*,
activedash: str | list[int] | Tuple[int, ...] = ...,
activedash: str | list[int] | tuple[int, ...] = ...,
activefill: _Color = ...,
activeoutline: _Color = ...,
activeoutlinestipple: _Color = ...,
activestipple: str = ...,
activewidth: _ScreenUnits = ...,
dash: str | list[int] | Tuple[int, ...] = ...,
dash: str | list[int] | tuple[int, ...] = ...,
dashoffset: _ScreenUnits = ...,
disableddash: str | list[int] | Tuple[int, ...] = ...,
disableddash: str | list[int] | tuple[int, ...] = ...,
disabledfill: _Color = ...,
disabledoutline: _Color = ...,
disabledoutlinestipple: _Color = ...,
@@ -1172,7 +1172,7 @@ class Canvas(Widget, XView, YView):
outlinestipple: _Bitmap = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@overload
@@ -1180,15 +1180,15 @@ class Canvas(Widget, XView, YView):
self,
__coords: tuple[float, float, float, float] | list[int] | list[float],
*,
activedash: str | list[int] | Tuple[int, ...] = ...,
activedash: str | list[int] | tuple[int, ...] = ...,
activefill: _Color = ...,
activeoutline: _Color = ...,
activeoutlinestipple: _Color = ...,
activestipple: str = ...,
activewidth: _ScreenUnits = ...,
dash: str | list[int] | Tuple[int, ...] = ...,
dash: str | list[int] | tuple[int, ...] = ...,
dashoffset: _ScreenUnits = ...,
disableddash: str | list[int] | Tuple[int, ...] = ...,
disableddash: str | list[int] | tuple[int, ...] = ...,
disabledfill: _Color = ...,
disabledoutline: _Color = ...,
disabledoutlinestipple: _Color = ...,
@@ -1201,7 +1201,7 @@ class Canvas(Widget, XView, YView):
outlinestipple: _Bitmap = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@overload
@@ -1212,15 +1212,15 @@ class Canvas(Widget, XView, YView):
__x1: float,
__y1: float,
*xy_pairs: float,
activedash: str | list[int] | Tuple[int, ...] = ...,
activedash: str | list[int] | tuple[int, ...] = ...,
activefill: _Color = ...,
activeoutline: _Color = ...,
activeoutlinestipple: _Color = ...,
activestipple: str = ...,
activewidth: _ScreenUnits = ...,
dash: str | list[int] | Tuple[int, ...] = ...,
dash: str | list[int] | tuple[int, ...] = ...,
dashoffset: _ScreenUnits = ...,
disableddash: str | list[int] | Tuple[int, ...] = ...,
disableddash: str | list[int] | tuple[int, ...] = ...,
disabledfill: _Color = ...,
disabledoutline: _Color = ...,
disabledoutlinestipple: _Color = ...,
@@ -1236,23 +1236,23 @@ class Canvas(Widget, XView, YView):
splinesteps: float = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@overload
def create_polygon(
self,
__coords: Tuple[float, ...] | list[int] | list[float],
__coords: tuple[float, ...] | list[int] | list[float],
*,
activedash: str | list[int] | Tuple[int, ...] = ...,
activedash: str | list[int] | tuple[int, ...] = ...,
activefill: _Color = ...,
activeoutline: _Color = ...,
activeoutlinestipple: _Color = ...,
activestipple: str = ...,
activewidth: _ScreenUnits = ...,
dash: str | list[int] | Tuple[int, ...] = ...,
dash: str | list[int] | tuple[int, ...] = ...,
dashoffset: _ScreenUnits = ...,
disableddash: str | list[int] | Tuple[int, ...] = ...,
disableddash: str | list[int] | tuple[int, ...] = ...,
disabledfill: _Color = ...,
disabledoutline: _Color = ...,
disabledoutlinestipple: _Color = ...,
@@ -1268,7 +1268,7 @@ class Canvas(Widget, XView, YView):
splinesteps: float = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@overload
@@ -1279,15 +1279,15 @@ class Canvas(Widget, XView, YView):
__x1: float,
__y1: float,
*,
activedash: str | list[int] | Tuple[int, ...] = ...,
activedash: str | list[int] | tuple[int, ...] = ...,
activefill: _Color = ...,
activeoutline: _Color = ...,
activeoutlinestipple: _Color = ...,
activestipple: str = ...,
activewidth: _ScreenUnits = ...,
dash: str | list[int] | Tuple[int, ...] = ...,
dash: str | list[int] | tuple[int, ...] = ...,
dashoffset: _ScreenUnits = ...,
disableddash: str | list[int] | Tuple[int, ...] = ...,
disableddash: str | list[int] | tuple[int, ...] = ...,
disabledfill: _Color = ...,
disabledoutline: _Color = ...,
disabledoutlinestipple: _Color = ...,
@@ -1300,7 +1300,7 @@ class Canvas(Widget, XView, YView):
outlinestipple: _Bitmap = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@overload
@@ -1308,15 +1308,15 @@ class Canvas(Widget, XView, YView):
self,
__coords: tuple[float, float, float, float] | list[int] | list[float],
*,
activedash: str | list[int] | Tuple[int, ...] = ...,
activedash: str | list[int] | tuple[int, ...] = ...,
activefill: _Color = ...,
activeoutline: _Color = ...,
activeoutlinestipple: _Color = ...,
activestipple: str = ...,
activewidth: _ScreenUnits = ...,
dash: str | list[int] | Tuple[int, ...] = ...,
dash: str | list[int] | tuple[int, ...] = ...,
dashoffset: _ScreenUnits = ...,
disableddash: str | list[int] | Tuple[int, ...] = ...,
disableddash: str | list[int] | tuple[int, ...] = ...,
disabledfill: _Color = ...,
disabledoutline: _Color = ...,
disabledoutlinestipple: _Color = ...,
@@ -1329,7 +1329,7 @@ class Canvas(Widget, XView, YView):
outlinestipple: _Bitmap = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@overload
@@ -1349,7 +1349,7 @@ class Canvas(Widget, XView, YView):
offset: _ScreenUnits = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
text: float | str = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@@ -1369,7 +1369,7 @@ class Canvas(Widget, XView, YView):
offset: _ScreenUnits = ...,
state: Literal["normal", "active", "disabled"] = ...,
stipple: _Bitmap = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
text: float | str = ...,
width: _ScreenUnits = ...,
) -> _CanvasItemId: ...
@@ -1382,7 +1382,7 @@ class Canvas(Widget, XView, YView):
anchor: _Anchor = ...,
height: _ScreenUnits = ...,
state: Literal["normal", "active", "disabled"] = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
window: Widget = ...,
) -> _CanvasItemId: ...
@@ -1394,7 +1394,7 @@ class Canvas(Widget, XView, YView):
anchor: _Anchor = ...,
height: _ScreenUnits = ...,
state: Literal["normal", "active", "disabled"] = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
width: _ScreenUnits = ...,
window: Widget = ...,
) -> _CanvasItemId: ...
@@ -1405,7 +1405,7 @@ class Canvas(Widget, XView, YView):
@overload
def dtag(self, __id: _CanvasItemId, __tag_to_delete: str) -> None: ...
def focus(self, *args): ...
def gettags(self, __tagOrId: str | _CanvasItemId) -> Tuple[str, ...]: ...
def gettags(self, __tagOrId: str | _CanvasItemId) -> tuple[str, ...]: ...
def icursor(self, *args): ...
def index(self, *args): ...
def insert(self, *args): ...
@@ -2650,7 +2650,7 @@ class Text(Widget, XView, YView):
startline: int | Literal[""] = ...,
state: Literal["normal", "disabled"] = ...,
# Literal inside Tuple doesn't actually work
tabs: _ScreenUnits | str | Tuple[_ScreenUnits | str, ...] = ...,
tabs: _ScreenUnits | str | tuple[_ScreenUnits | str, ...] = ...,
tabstyle: Literal["tabular", "wordprocessor"] = ...,
takefocus: _TakeFocusValue = ...,
undo: bool = ...,
@@ -2701,7 +2701,7 @@ class Text(Widget, XView, YView):
spacing3: _ScreenUnits = ...,
startline: int | Literal[""] = ...,
state: Literal["normal", "disabled"] = ...,
tabs: _ScreenUnits | str | Tuple[_ScreenUnits | str, ...] = ...,
tabs: _ScreenUnits | str | tuple[_ScreenUnits | str, ...] = ...,
tabstyle: Literal["tabular", "wordprocessor"] = ...,
takefocus: _TakeFocusValue = ...,
undo: bool = ...,
@@ -2780,20 +2780,20 @@ class Text(Widget, XView, YView):
def image_create(self, index, cnf=..., **kw): ...
def image_names(self): ...
def index(self, index: _TextIndex) -> str: ...
def insert(self, index: _TextIndex, chars: str, *args: str | list[str] | Tuple[str, ...]) -> None: ...
def insert(self, index: _TextIndex, chars: str, *args: str | list[str] | tuple[str, ...]) -> None: ...
@overload
def mark_gravity(self, markName: str, direction: None = ...) -> Literal["left", "right"]: ...
@overload
def mark_gravity(self, markName: str, direction: Literal["left", "right"]) -> None: ... # actually returns empty string
def mark_names(self) -> Tuple[str, ...]: ...
def mark_names(self) -> tuple[str, ...]: ...
def mark_set(self, markName: str, index: _TextIndex) -> None: ...
def mark_unset(self, *markNames: str) -> None: ...
def mark_next(self, index: _TextIndex) -> str | None: ...
def mark_previous(self, index: _TextIndex) -> str | None: ...
# **kw of peer_create is same as the kwargs of Text.__init__
def peer_create(self, newPathName: str | Text, cnf: dict[str, Any] = ..., **kw: Any) -> None: ...
def peer_names(self) -> Tuple[_tkinter.Tcl_Obj, ...]: ...
def replace(self, index1: _TextIndex, index2: _TextIndex, chars: str, *args: str | list[str] | Tuple[str, ...]) -> None: ...
def peer_names(self) -> tuple[_tkinter.Tcl_Obj, ...]: ...
def replace(self, index1: _TextIndex, index2: _TextIndex, chars: str, *args: str | list[str] | tuple[str, ...]) -> None: ...
def scan_mark(self, x: int, y: int) -> None: ...
def scan_dragto(self, x: int, y: int) -> None: ...
def search(
@@ -2865,11 +2865,11 @@ class Text(Widget, XView, YView):
tag_config = tag_configure
def tag_delete(self, __first_tag_name: str, *tagNames: str) -> None: ... # error if no tag names given
def tag_lower(self, tagName: str, belowThis: str | None = ...) -> None: ...
def tag_names(self, index: _TextIndex | None = ...) -> Tuple[str, ...]: ...
def tag_names(self, index: _TextIndex | None = ...) -> tuple[str, ...]: ...
def tag_nextrange(self, tagName: str, index1: _TextIndex, index2: _TextIndex | None = ...) -> tuple[str, str] | tuple[()]: ...
def tag_prevrange(self, tagName: str, index1: _TextIndex, index2: _TextIndex | None = ...) -> tuple[str, str] | tuple[()]: ...
def tag_raise(self, tagName: str, aboveThis: str | None = ...) -> None: ...
def tag_ranges(self, tagName: str) -> Tuple[_tkinter.Tcl_Obj, ...]: ...
def tag_ranges(self, tagName: str) -> tuple[_tkinter.Tcl_Obj, ...]: ...
# tag_remove and tag_delete are different
def tag_remove(self, tagName: str, index1: _TextIndex, index2: _TextIndex | None = ...) -> None: ...
# TODO: window_* methods
@@ -2959,10 +2959,10 @@ class PhotoImage(Image):
str
| list[str]
| list[list[_Color]]
| list[Tuple[_Color, ...]]
| Tuple[str, ...]
| Tuple[list[_Color], ...]
| Tuple[Tuple[_Color, ...], ...]
| list[tuple[_Color, ...]]
| tuple[str, ...]
| tuple[list[_Color], ...]
| tuple[tuple[_Color, ...], ...]
),
to: tuple[int, int] | None = ...,
) -> None: ...
@@ -2986,8 +2986,8 @@ class BitmapImage(Image):
maskfile: StrOrBytesPath = ...,
) -> None: ...
def image_names() -> Tuple[str, ...]: ...
def image_types() -> Tuple[str, ...]: ...
def image_names() -> tuple[str, ...]: ...
def image_types() -> tuple[str, ...]: ...
class Spinbox(Widget, XView):
def __init__(
@@ -3006,7 +3006,7 @@ class Spinbox(Widget, XView):
buttondownrelief: _Relief = ...,
buttonuprelief: _Relief = ...,
# percent substitutions don't seem to be supported, it's similar to Entry's validation stuff
command: Callable[[], Any] | str | list[str] | Tuple[str, ...] = ...,
command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ...,
cursor: _Cursor = ...,
disabledbackground: _Color = ...,
disabledforeground: _Color = ...,
@@ -3043,7 +3043,7 @@ class Spinbox(Widget, XView):
validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ...,
validatecommand: _EntryValidateCommand = ...,
vcmd: _EntryValidateCommand = ...,
values: list[str] | Tuple[str, ...] = ...,
values: list[str] | tuple[str, ...] = ...,
width: int = ...,
wrap: bool = ...,
xscrollcommand: _XYScrollCommand = ...,
@@ -3063,7 +3063,7 @@ class Spinbox(Widget, XView):
buttoncursor: _Cursor = ...,
buttondownrelief: _Relief = ...,
buttonuprelief: _Relief = ...,
command: Callable[[], Any] | str | list[str] | Tuple[str, ...] = ...,
command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ...,
cursor: _Cursor = ...,
disabledbackground: _Color = ...,
disabledforeground: _Color = ...,
@@ -3099,7 +3099,7 @@ class Spinbox(Widget, XView):
validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ...,
validatecommand: _EntryValidateCommand = ...,
vcmd: _EntryValidateCommand = ...,
values: list[str] | Tuple[str, ...] = ...,
values: list[str] | tuple[str, ...] = ...,
width: int = ...,
wrap: bool = ...,
xscrollcommand: _XYScrollCommand = ...,
@@ -3119,7 +3119,7 @@ class Spinbox(Widget, XView):
def scan(self, *args): ...
def scan_mark(self, x): ...
def scan_dragto(self, x): ...
def selection(self, *args: Any) -> Tuple[int, ...]: ...
def selection(self, *args: Any) -> tuple[int, ...]: ...
def selection_adjust(self, index): ...
def selection_clear(self): ...
def selection_element(self, element: Any | None = ...): ...

View File

@@ -1,6 +1,6 @@
from _typeshed import StrOrBytesPath
from tkinter import Button, Entry, Frame, Listbox, Misc, Scrollbar, StringVar, Toplevel, commondialog
from typing import IO, Any, ClassVar, Iterable, Tuple
from typing import IO, Any, ClassVar, Iterable
from typing_extensions import Literal
dialogstates: dict[Any, tuple[Any, Any]]
@@ -64,7 +64,7 @@ def asksaveasfilename(
*,
confirmoverwrite: bool | None = ...,
defaultextension: str | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | Tuple[str, ...]]] | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ...,
initialdir: StrOrBytesPath | None = ...,
initialfile: StrOrBytesPath | None = ...,
parent: Misc | None = ...,
@@ -74,7 +74,7 @@ def asksaveasfilename(
def askopenfilename(
*,
defaultextension: str | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | Tuple[str, ...]]] | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ...,
initialdir: StrOrBytesPath | None = ...,
initialfile: StrOrBytesPath | None = ...,
parent: Misc | None = ...,
@@ -84,13 +84,13 @@ def askopenfilename(
def askopenfilenames(
*,
defaultextension: str | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | Tuple[str, ...]]] | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ...,
initialdir: StrOrBytesPath | None = ...,
initialfile: StrOrBytesPath | None = ...,
parent: Misc | None = ...,
title: str | None = ...,
typevariable: StringVar | str | None = ...,
) -> Literal[""] | Tuple[str, ...]: ...
) -> Literal[""] | tuple[str, ...]: ...
def askdirectory(
*, initialdir: StrOrBytesPath | None = ..., mustexist: bool | None = ..., parent: Misc | None = ..., title: str | None = ...
) -> str: ... # can be empty string
@@ -101,7 +101,7 @@ def asksaveasfile(
*,
confirmoverwrite: bool | None = ...,
defaultextension: str | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | Tuple[str, ...]]] | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ...,
initialdir: StrOrBytesPath | None = ...,
initialfile: StrOrBytesPath | None = ...,
parent: Misc | None = ...,
@@ -112,7 +112,7 @@ def askopenfile(
mode: str = ...,
*,
defaultextension: str | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | Tuple[str, ...]]] | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ...,
initialdir: StrOrBytesPath | None = ...,
initialfile: StrOrBytesPath | None = ...,
parent: Misc | None = ...,
@@ -123,11 +123,11 @@ def askopenfiles(
mode: str = ...,
*,
defaultextension: str | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | Tuple[str, ...]]] | None = ...,
filetypes: Iterable[tuple[str, str | list[str] | tuple[str, ...]]] | None = ...,
initialdir: StrOrBytesPath | None = ...,
initialfile: StrOrBytesPath | None = ...,
parent: Misc | None = ...,
title: str | None = ...,
typevariable: StringVar | str | None = ...,
) -> Tuple[IO[Any], ...]: ... # can be empty tuple
) -> tuple[IO[Any], ...]: ... # can be empty tuple
def test() -> None: ...

View File

@@ -1,7 +1,7 @@
import _tkinter
import sys
import tkinter
from typing import Any, List, Tuple, Union, overload
from typing import Any, Union, overload
from typing_extensions import Literal, TypedDict
NORMAL: Literal["normal"]
@@ -15,8 +15,8 @@ _FontDescription = Union[
# A font object constructed in Python
Font,
# ("Helvetica", 12, BOLD)
List[Any],
Tuple[Any, ...],
list[Any],
tuple[Any, ...],
# A font object constructed in Tcl
_tkinter.Tcl_Obj,
]
@@ -102,8 +102,8 @@ class Font:
def metrics(self, *, displayof: tkinter.Misc | None = ...) -> _MetricsDict: ...
def measure(self, text: str, displayof: tkinter.Misc | None = ...) -> int: ...
def families(root: tkinter.Misc | None = ..., displayof: tkinter.Misc | None = ...) -> Tuple[str, ...]: ...
def names(root: tkinter.Misc | None = ...) -> Tuple[str, ...]: ...
def families(root: tkinter.Misc | None = ..., displayof: tkinter.Misc | None = ...) -> tuple[str, ...]: ...
def names(root: tkinter.Misc | None = ...) -> tuple[str, ...]: ...
if sys.version_info >= (3, 10):
def nametofont(name: str, root: tkinter.Misc | None = ...) -> Font: ...

View File

@@ -1,5 +1,5 @@
import tkinter
from typing import Any, Tuple
from typing import Any
from typing_extensions import Literal
WINDOW: Literal["window"]
@@ -194,7 +194,7 @@ class HList(TixWidget, tkinter.XView, tkinter.YView):
def indicator_size(self, entry: str) -> int: ...
def info_anchor(self) -> str: ...
def info_bbox(self, entry: str) -> tuple[int, int, int, int]: ...
def info_children(self, entry: str | None = ...) -> Tuple[str, ...]: ...
def info_children(self, entry: str | None = ...) -> tuple[str, ...]: ...
def info_data(self, entry: str) -> Any: ...
def info_dragsite(self) -> str: ...
def info_dropsite(self) -> str: ...
@@ -203,7 +203,7 @@ class HList(TixWidget, tkinter.XView, tkinter.YView):
def info_next(self, entry: str) -> str: ...
def info_parent(self, entry: str) -> str: ...
def info_prev(self, entry: str) -> str: ...
def info_selection(self) -> Tuple[str, ...]: ...
def info_selection(self) -> tuple[str, ...]: ...
def item_cget(self, entry: str, col: int, opt: Any) -> Any: ...
def item_configure(self, entry: str, col: int, cnf: dict[str, Any] = ..., **kw: Any) -> Any | None: ...
def item_create(self, entry: str, col: int, cnf: dict[str, Any] = ..., **kw: Any) -> None: ...
@@ -224,7 +224,7 @@ class CheckList(TixWidget):
def close(self, entrypath: str) -> None: ...
def getmode(self, entrypath: str) -> str: ...
def open(self, entrypath: str) -> None: ...
def getselection(self, mode: str = ...) -> Tuple[str, ...]: ...
def getselection(self, mode: str = ...) -> tuple[str, ...]: ...
def getstatus(self, entrypath: str) -> str: ...
def setstatus(self, entrypath: str, mode: str = ...) -> None: ...
@@ -253,7 +253,7 @@ class TList(TixWidget, tkinter.XView, tkinter.YView):
def info_down(self, index: int) -> int: ...
def info_left(self, index: int) -> int: ...
def info_right(self, index: int) -> int: ...
def info_selection(self) -> Tuple[int, ...]: ...
def info_selection(self) -> tuple[int, ...]: ...
def info_size(self) -> int: ...
def info_up(self, index: int) -> int: ...
def nearest(self, x: int, y: int) -> int: ...

View File

@@ -2,7 +2,7 @@ import _tkinter
import sys
import tkinter
from tkinter.font import _FontDescription
from typing import Any, Callable, Tuple, Union, overload
from typing import Any, Callable, Union, overload
from typing_extensions import Literal, TypedDict
def tclobjs_to_py(adict): ...
@@ -24,7 +24,7 @@ class Style:
def element_options(self, elementname): ...
def theme_create(self, themename, parent: Any | None = ..., settings: Any | None = ...): ...
def theme_settings(self, themename, settings): ...
def theme_names(self) -> Tuple[str, ...]: ...
def theme_names(self) -> tuple[str, ...]: ...
@overload
def theme_use(self, themename: str) -> None: ...
@overload
@@ -234,7 +234,7 @@ class Combobox(Entry):
textvariable: tkinter.Variable = ...,
validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., # undocumented
validatecommand: tkinter._EntryValidateCommand = ..., # undocumented
values: list[str] | Tuple[str, ...] = ...,
values: list[str] | tuple[str, ...] = ...,
width: int = ...,
xscrollcommand: tkinter._XYScrollCommand = ..., # undocumented
) -> None: ...
@@ -259,7 +259,7 @@ class Combobox(Entry):
textvariable: tkinter.Variable = ...,
validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ...,
validatecommand: tkinter._EntryValidateCommand = ...,
values: list[str] | Tuple[str, ...] = ...,
values: list[str] | tuple[str, ...] = ...,
width: int = ...,
xscrollcommand: tkinter._XYScrollCommand = ...,
) -> dict[str, tuple[str, str, str, Any, Any]] | None: ...
@@ -287,7 +287,7 @@ class Combobox(Entry):
textvariable: tkinter.Variable = ...,
validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ...,
validatecommand: tkinter._EntryValidateCommand = ...,
values: list[str] | Tuple[str, ...] = ...,
values: list[str] | tuple[str, ...] = ...,
width: int = ...,
xscrollcommand: tkinter._XYScrollCommand = ...,
) -> dict[str, tuple[str, str, str, Any, Any]] | None: ...
@@ -828,7 +828,7 @@ if sys.version_info >= (3, 7):
*,
background: tkinter._Color = ..., # undocumented
class_: str = ...,
command: Callable[[], Any] | str | list[str] | Tuple[str, ...] = ...,
command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ...,
cursor: tkinter._Cursor = ...,
exportselection: bool = ..., # undocumented
font: _FontDescription = ..., # undocumented
@@ -847,7 +847,7 @@ if sys.version_info >= (3, 7):
to: float = ...,
validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ...,
validatecommand: tkinter._EntryValidateCommand = ...,
values: list[str] | Tuple[str, ...] = ...,
values: list[str] | tuple[str, ...] = ...,
width: int = ..., # undocumented
wrap: bool = ...,
xscrollcommand: tkinter._XYScrollCommand = ...,
@@ -858,7 +858,7 @@ if sys.version_info >= (3, 7):
cnf: dict[str, Any] | None = ...,
*,
background: tkinter._Color = ...,
command: Callable[[], Any] | str | list[str] | Tuple[str, ...] = ...,
command: Callable[[], Any] | str | list[str] | tuple[str, ...] = ...,
cursor: tkinter._Cursor = ...,
exportselection: bool = ...,
font: _FontDescription = ...,
@@ -876,7 +876,7 @@ if sys.version_info >= (3, 7):
to: float = ...,
validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ...,
validatecommand: tkinter._EntryValidateCommand = ...,
values: list[str] | Tuple[str, ...] = ...,
values: list[str] | tuple[str, ...] = ...,
width: int = ...,
wrap: bool = ...,
xscrollcommand: tkinter._XYScrollCommand = ...,
@@ -922,9 +922,9 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
master: tkinter.Misc | None = ...,
*,
class_: str = ...,
columns: str | list[str] | Tuple[str, ...] = ...,
columns: str | list[str] | tuple[str, ...] = ...,
cursor: tkinter._Cursor = ...,
displaycolumns: str | list[str] | Tuple[str, ...] | list[int] | Tuple[int, ...] | Literal["#all"] = ...,
displaycolumns: str | list[str] | tuple[str, ...] | list[int] | tuple[int, ...] | Literal["#all"] = ...,
height: int = ...,
name: str = ...,
padding: tkinter._Padding = ...,
@@ -933,7 +933,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
#
# 'tree headings' is same as ['tree', 'headings'], and I wouldn't be
# surprised if someone is using it.
show: Literal["tree", "headings", "tree headings", ""] | list[str] | Tuple[str, ...] = ...,
show: Literal["tree", "headings", "tree headings", ""] | list[str] | tuple[str, ...] = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
xscrollcommand: tkinter._XYScrollCommand = ...,
@@ -944,13 +944,13 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
self,
cnf: dict[str, Any] | None = ...,
*,
columns: str | list[str] | Tuple[str, ...] = ...,
columns: str | list[str] | tuple[str, ...] = ...,
cursor: tkinter._Cursor = ...,
displaycolumns: str | list[str] | Tuple[str, ...] | list[int] | Tuple[int, ...] | Literal["#all"] = ...,
displaycolumns: str | list[str] | tuple[str, ...] | list[int] | tuple[int, ...] | Literal["#all"] = ...,
height: int = ...,
padding: tkinter._Padding = ...,
selectmode: Literal["extended", "browse", "none"] = ...,
show: Literal["tree", "headings", "tree headings", ""] | list[str] | Tuple[str, ...] = ...,
show: Literal["tree", "headings", "tree headings", ""] | list[str] | tuple[str, ...] = ...,
style: str = ...,
takefocus: tkinter._TakeFocusValue = ...,
xscrollcommand: tkinter._XYScrollCommand = ...,
@@ -960,7 +960,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
def configure(self, cnf: str) -> tuple[str, str, str, Any, Any]: ...
config = configure
def bbox(self, item, column: _TreeviewColumnId | None = ...) -> tuple[int, int, int, int] | Literal[""]: ... # type: ignore[override]
def get_children(self, item: str | None = ...) -> Tuple[str, ...]: ...
def get_children(self, item: str | None = ...) -> tuple[str, ...]: ...
def set_children(self, item: str, *newchildren: str) -> None: ...
@overload
def column(self, column: _TreeviewColumnId, option: Literal["width", "minwidth"]) -> int: ...
@@ -1027,20 +1027,20 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
id: str = ..., # same as iid
text: str = ...,
image: tkinter._ImageSpec = ...,
values: list[Any] | Tuple[Any, ...] = ...,
values: list[Any] | tuple[Any, ...] = ...,
open: bool = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
) -> str: ...
@overload
def item(self, item: str, option: Literal["text"]) -> str: ...
@overload
def item(self, item: str, option: Literal["image"]) -> tuple[str] | Literal[""]: ...
@overload
def item(self, item: str, option: Literal["values"]) -> Tuple[Any, ...] | Literal[""]: ...
def item(self, item: str, option: Literal["values"]) -> tuple[Any, ...] | Literal[""]: ...
@overload
def item(self, item: str, option: Literal["open"]) -> bool: ... # actually 0 or 1
@overload
def item(self, item: str, option: Literal["tags"]) -> Tuple[str, ...] | Literal[""]: ...
def item(self, item: str, option: Literal["tags"]) -> tuple[str, ...] | Literal[""]: ...
@overload
def item(self, item: str, option: str) -> Any: ...
@overload
@@ -1051,9 +1051,9 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
*,
text: str = ...,
image: tkinter._ImageSpec = ...,
values: list[Any] | Tuple[Any, ...] | Literal[""] = ...,
values: list[Any] | tuple[Any, ...] | Literal[""] = ...,
open: bool = ...,
tags: str | list[str] | Tuple[str, ...] = ...,
tags: str | list[str] | tuple[str, ...] = ...,
) -> _TreeviewItemDict | None: ...
def move(self, item: str, parent: str, index: int) -> None: ...
reattach = move
@@ -1062,13 +1062,13 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
def prev(self, item: str) -> str: ... # returning empty string means first item
def see(self, item: str) -> None: ...
if sys.version_info >= (3, 8):
def selection(self) -> Tuple[str, ...]: ...
def selection(self) -> tuple[str, ...]: ...
else:
def selection(self, selop: Any | None = ..., items: Any | None = ...) -> Tuple[str, ...]: ...
def selection_set(self, items: str | list[str] | Tuple[str, ...]) -> None: ...
def selection_add(self, items: str | list[str] | Tuple[str, ...]) -> None: ...
def selection_remove(self, items: str | list[str] | Tuple[str, ...]) -> None: ...
def selection_toggle(self, items: str | list[str] | Tuple[str, ...]) -> None: ...
def selection(self, selop: Any | None = ..., items: Any | None = ...) -> tuple[str, ...]: ...
def selection_set(self, items: str | list[str] | tuple[str, ...]) -> None: ...
def selection_add(self, items: str | list[str] | tuple[str, ...]) -> None: ...
def selection_remove(self, items: str | list[str] | tuple[str, ...]) -> None: ...
def selection_toggle(self, items: str | list[str] | tuple[str, ...]) -> None: ...
@overload
def set(self, item: str, column: None = ..., value: None = ...) -> dict[str, Any]: ...
@overload
@@ -1104,7 +1104,7 @@ class Treeview(Widget, tkinter.XView, tkinter.YView):
image: tkinter._ImageSpec = ...,
) -> _TreeviewTagDict | Any: ... # can be None but annoying to check
@overload
def tag_has(self, tagname: str, item: None = ...) -> Tuple[str, ...]: ...
def tag_has(self, tagname: str, item: None = ...) -> tuple[str, ...]: ...
@overload
def tag_has(self, tagname: str, item: str) -> bool: ...