diff --git a/requirements-tests-py3.txt b/requirements-tests-py3.txt index 44832310f88d..dfd31e6fbb18 100644 --- a/requirements-tests-py3.txt +++ b/requirements-tests-py3.txt @@ -5,4 +5,4 @@ flake8==3.8.3 flake8-bugbear==20.1.4 flake8-pyi==20.5.0 isort[pyproject]==5.1.1 -pytype>=2020.07.24 +pytype>=2020.07.30 diff --git a/stdlib/3/tkinter/__init__.pyi b/stdlib/3/tkinter/__init__.pyi index ad4e1056cd1c..b06043619dad 100644 --- a/stdlib/3/tkinter/__init__.pyi +++ b/stdlib/3/tkinter/__init__.pyi @@ -1,11 +1,16 @@ import _tkinter import sys from enum import Enum -from tkinter.constants import * # noqa: F403 +from tkinter.constants import * # comment this out to find undefined identifier names with flake8 +from tkinter.font import _FontDescription from types import TracebackType from typing import Any, Callable, Dict, Generic, List, Optional, Tuple, Type, TypeVar, Union, overload from typing_extensions import Literal, TypedDict +# Using anything from tkinter.font in this file means that 'import tkinter' +# seems to also load tkinter.font. That's not how it actually works, but +# unfortunately not much can be done about it. https://github.com/python/typeshed/pull/4346 + TclError = _tkinter.TclError wantobjects: Any TkVersion: Any @@ -14,15 +19,94 @@ READABLE = _tkinter.READABLE WRITABLE = _tkinter.WRITABLE EXCEPTION = _tkinter.EXCEPTION -# If a manual page mentions Tk_GetAnchor or refers to another manual page named -# 'options', then it means this. Note that some ttk widgets have other things -# named 'anchor' with a different set of allowed values. -_Anchor = Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] +# Quick guide for figuring out which widget class to choose: +# - Misc: any widget (don't use BaseWidget because Tk doesn't inherit from BaseWidget) +# - Widget: anything that is meant to be put into another widget with e.g. pack or grid +# - Wm: a toplevel window, Tk or Toplevel +# +# Instructions for figuring out the correct type of each widget option: +# - See discussion on #4363. +# +# - Find the option from the manual page of the widget. Usually the manual +# page of a non-ttk widget has the same name as the tkinter class, in the +# 3tk section: +# +# $ sudo apt install tk-doc +# $ man 3tk label +# +# Ttk manual pages tend to have ttk_ prefixed names: +# +# $ man 3tk ttk_label +# +# Non-GUI things like the .after() method are often in the 3tcl section: +# +# $ sudo apt install tcl-doc +# $ man 3tcl after +# +# If you don't have man or apt, you can read these manual pages online: +# +# https://www.tcl.tk/doc/ +# +# Every option has '-' in front of its name in the manual page (and in Tcl). +# For example, there's an option named '-text' in the label manual page. +# +# - Tkinter has some options documented in docstrings, but don't rely on them. +# They aren't updated when a new version of Tk comes out, so the latest Tk +# manual pages (see above) are much more likely to actually contain all +# possible options. +# +# Also, reading tkinter's source code typically won't help much because it +# uses a lot of **kwargs and duck typing. Typically every argument goes into +# self.tk.call, which is _tkinter.TkappType.call, and the return value is +# whatever that returns. The type of that depends on how the Tcl interpreter +# represents the return value of the executed Tcl code. +# +# - If you think that int is an appropriate type for something, then you may +# actually want _ScreenUnits instead. +# +# - If you think that Callable[something] is an appropriate type for +# something, then you may actually want Union[Callable[something], str], +# because it's often possible to specify a string of Tcl code. +# +# - Some options can be set only in __init__, but all options are available +# when getting their values with configure's return value or cget. +# +# - Asks other tkinter users if you haven't worked much with tkinter. + +# _TkinterSequence[T] represents a sequence that tkinter understands. It +# differs from typing.Sequence[T]. For example, collections.deque a valid +# Sequence but not a valid _TkinterSequence: +# +# >>> tkinter.Label(font=('Helvetica', 12, collections.deque(['bold']))) +# Traceback (most recent call last): +# ... +# _tkinter.TclError: unknown font style "deque(['bold'])" +_T = TypeVar("_T") +_TkinterSequence = Union[List[_T], Tuple[_T, ...]] -# string must be e.g. '12.34', '12.34c', '12.34i', '12.34m', '12.34p' -# see Tk_GetPixels man page for what each suffix means -# Some ttk widgets also use empty string. -_ScreenUnits = Union[str, float] +# Some widgets have an option named -compound that accepts different values +# than the _Compound defined here. Many other options have similar things. +_Anchor = Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] # manual page: Tk_GetAnchor +_Bitmap = str # manual page: Tk_GetBitmap +_ButtonCommand = Union[str, Callable[[], Any]] # return value is returned from Button.invoke() +_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 +_EntryValidateCommand = Union[ + Callable[[], bool], str, _TkinterSequence[str] +] # example when it's sequence: entry['invalidcommand'] = [entry.register(print), '%P'] +_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], +] +_Relief = Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] # manual page: Tk_GetRelief +_ScreenUnits = Union[str, float] # manual page: Tk_GetPixels +_XYScrollCommand = Union[str, Callable[[float, float], None]] # -xscrollcommand and -yscrollcommand in 'options' manual page +_TakeFocusValue = Union[bool, Literal[""], Callable[[str], Optional[bool]]] # -takefocus in manual page named 'options' if sys.version_info >= (3, 6): class EventType(str, Enum): @@ -140,8 +224,6 @@ getdouble: Any def getboolean(s): ... -# This class is the base class of all widgets. Don't use BaseWidget or Widget -# for that because Tk doesn't inherit from Widget or BaseWidget. class Misc: tk: _tkinter.TkappType def destroy(self): ... @@ -291,12 +373,7 @@ class Misc: def quit(self): ... def nametowidget(self, name): ... register: Any - def configure(self, cnf: Optional[Any] = ..., **kw): ... - config = configure - def cget(self, key): ... - __getitem__: Any - def __setitem__(self, key, value): ... - def keys(self): ... + def keys(self) -> List[str]: ... @overload def pack_propagate(self, flag: bool) -> Optional[bool]: ... @overload @@ -336,6 +413,9 @@ class Misc: def event_info(self, virtual: Optional[Any] = ...): ... def image_names(self): ... def image_types(self): ... + # See #4363 + def __setitem__(self, key: str, value: Any) -> None: ... + def __getitem__(self, key: str) -> Any: ... class CallWrapper: func: Any @@ -430,6 +510,31 @@ class Wm: def wm_withdraw(self): ... withdraw: Any +_TkOptionName = Literal[ + "background", + "bd", + "bg", + "border", + "borderwidth", + "class", + "colormap", + "container", + "cursor", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "menu", + "padx", + "pady", + "relief", + "screen", # can't be changed after creating widget + "takefocus", + "use", + "visual", + "width", +] + class Tk(Misc, Wm): master: Optional[Any] children: Dict[str, Any] @@ -442,6 +547,32 @@ class Tk(Misc, Wm): sync: bool = ..., use: Optional[str] = ..., ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + menu: Menu = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + takefocus: _TakeFocusValue = ..., + width: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _TkOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _TkOptionName) -> Any: ... def loadtk(self) -> None: ... # differs from _tkinter.TkappType.loadtk def destroy(self) -> None: ... def readprofile(self, baseName: str, className: str) -> None: ... @@ -649,15 +780,291 @@ class Widget(BaseWidget, Pack, Place, Grid): def bind(self, *, func: str, add: Optional[bool] = ...) -> None: ... class Toplevel(BaseWidget, Wm): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + class_: str = ..., + colormap: Union[Literal["new", ""], Misc] = ..., + container: bool = ..., + cursor: _Cursor = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + menu: Menu = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + screen: str = ..., + takefocus: _TakeFocusValue = ..., + use: int = ..., + visual: Union[str, Tuple[str, int]] = ..., + width: _ScreenUnits = ..., + ) -> None: ... + # Toplevel and Tk have the same options because they correspond to the same + # Tcl/Tk toplevel widget. + configure = Tk.configure + config = Tk.config + cget = Tk.cget + +_ButtonOptionName = Literal[ + "activebackground", + "activeforeground", + "anchor", + "background", + "bd", # same as borderwidth + "bg", # same as background + "bitmap", + "border", # same as borderwidth + "borderwidth", + "command", + "compound", + "cursor", + "default", + "disabledforeground", + "fg", # same as foreground + "font", + "foreground", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "image", + "justify", + "overrelief", + "padx", + "pady", + "relief", + "repeatdelay", + "repeatinterval", + "state", + "takefocus", + "text", + "textvariable", + "underline", + "width", + "wraplength", +] class Button(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + command: _ButtonCommand = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + default: Literal["normal", "active", "disabled"] = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + # width and height must be int for buttons containing just text, but + # ints are also valid _ScreenUnits + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + justify: Literal["left", "center", "right"] = ..., + overrelief: _Relief = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + repeatdelay: int = ..., + repeatinterval: int = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + # We allow the textvariable to be any Variable, not necessarly + # StringVar. This is useful for e.g. a button that displays the value + # of an IntVar. + textvariable: Variable = ..., + underline: int = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + command: _ButtonCommand = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + default: Literal["normal", "active", "disabled"] = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + justify: Literal["left", "center", "right"] = ..., + overrelief: _Relief = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + repeatdelay: int = ..., + repeatinterval: int = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + underline: int = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _ButtonOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _ButtonOptionName) -> Any: ... def flash(self): ... def invoke(self): ... +_CanvasOptionName = Literal[ + "background", + "bd", + "bg", + "border", + "borderwidth", + "closeenough", + "confine", + "cursor", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "insertbackground", + "insertborderwidth", + "insertofftime", + "insertontime", + "insertwidth", + "offset", + "relief", + "scrollregion", + "selectbackground", + "selectborderwidth", + "selectforeground", + "state", + "takefocus", + "width", + "xscrollcommand", + "xscrollincrement", + "yscrollcommand", + "yscrollincrement", +] + class Canvas(Widget, XView, YView): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + closeenough: float = ..., + confine: bool = ..., + cursor: _Cursor = ..., + # canvas manual page has a section named COORDINATES, and the first + # part of it describes _ScreenUnits. + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + insertbackground: _Color = ..., + insertborderwidth: _ScreenUnits = ..., + insertofftime: int = ..., + insertontime: int = ..., + insertwidth: _ScreenUnits = ..., + offset: Any, # undocumented + relief: _Relief = ..., + # Setting scrollregion to None doesn't reset it back to empty, + # but setting it to () does. + scrollregion: Union[Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _ScreenUnits], Tuple[()]] = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + # man page says that state can be 'hidden', but it can't + state: Literal["normal", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + width: _ScreenUnits = ..., + xscrollcommand: _XYScrollCommand = ..., + xscrollincrement: _ScreenUnits = ..., + yscrollcommand: _XYScrollCommand = ..., + yscrollincrement: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + closeenough: float = ..., + confine: bool = ..., + cursor: _Cursor = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + insertbackground: _Color = ..., + insertborderwidth: _ScreenUnits = ..., + insertofftime: int = ..., + insertontime: int = ..., + insertwidth: _ScreenUnits = ..., + offset: Any, # undocumented + relief: _Relief = ..., + scrollregion: Union[Tuple[_ScreenUnits, _ScreenUnits, _ScreenUnits, _ScreenUnits], Tuple[()]] = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + state: Literal["normal", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + width: _ScreenUnits = ..., + xscrollcommand: _XYScrollCommand = ..., + xscrollincrement: _ScreenUnits = ..., + yscrollcommand: _XYScrollCommand = ..., + yscrollincrement: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _CanvasOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _CanvasOptionName) -> Any: ... def addtag(self, *args): ... def addtag_above(self, newtag, tagOrId): ... def addtag_all(self, newtag): ... @@ -729,16 +1136,299 @@ class Canvas(Widget, XView, YView): def select_to(self, tagOrId, index): ... def type(self, tagOrId): ... +_CheckbuttonOptionName = Literal[ + "activebackground", + "activeforeground", + "anchor", + "background", + "bd", + "bg", + "bitmap", + "border", + "borderwidth", + "command", + "compound", + "cursor", + "disabledforeground", + "fg", + "font", + "foreground", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "image", + "indicatoron", + "justify", + "offrelief", + "offvalue", + "onvalue", + "overrelief", + "padx", + "pady", + "relief", + "selectcolor", + "selectimage", + "state", + "takefocus", + "text", + "textvariable", + "tristateimage", + "tristatevalue", + "underline", + "variable", + "width", + "wraplength", +] + class Checkbutton(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + command: _ButtonCommand = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + indicatoron: bool = ..., + justify: Literal["left", "center", "right"] = ..., + offrelief: _Relief = ..., + # The checkbutton puts a value to its variable when it's checked or + # unchecked. We don't restrict the type of that value here, so + # Any-typing is fine. + # + # I think Checkbutton shouldn't be generic, because then specifying + # "any checkbutton regardless of what variable it uses" would be + # difficult, and we might run into issues just like how List[float] + # and List[int] are incompatible. Also, we would need a way to + # specify "Checkbutton not associated with any variable", which is + # done by setting variable to empty string (the default). + offvalue: Any = ..., + onvalue: Any = ..., + overrelief: _Relief = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + selectcolor: _Color = ..., + selectimage: _ImageSpec = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + tristateimage: _ImageSpec = ..., + tristatevalue: Any = ..., + underline: int = ..., + variable: Union[Variable, Literal[""]] = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + command: _ButtonCommand = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + indicatoron: bool = ..., + justify: Literal["left", "center", "right"] = ..., + offrelief: _Relief = ..., + offvalue: Any = ..., + onvalue: Any = ..., + overrelief: _Relief = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + selectcolor: _Color = ..., + selectimage: _ImageSpec = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + tristateimage: _ImageSpec = ..., + tristatevalue: Any = ..., + underline: int = ..., + variable: Union[Variable, Literal[""]] = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _CheckbuttonOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _CheckbuttonOptionName) -> Any: ... def deselect(self): ... def flash(self): ... def invoke(self): ... def select(self): ... def toggle(self): ... +_EntryOptionName = Literal[ + "background", + "bd", + "bg", + "border", + "borderwidth", + "cursor", + "disabledbackground", + "disabledforeground", + "exportselection", + "fg", + "font", + "foreground", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "insertbackground", + "insertborderwidth", + "insertofftime", + "insertontime", + "insertwidth", + "invalidcommand", + "invcmd", # same as invalidcommand + "justify", + "readonlybackground", + "relief", + "selectbackground", + "selectborderwidth", + "selectforeground", + "show", + "state", + "takefocus", + "textvariable", + "validate", + "validatecommand", + "vcmd", # same as validatecommand + "width", + "xscrollcommand", +] + class Entry(Widget, XView): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + disabledbackground: _Color = ..., + disabledforeground: _Color = ..., + exportselection: bool = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + insertbackground: _Color = ..., + insertborderwidth: _ScreenUnits = ..., + insertofftime: int = ..., + insertontime: int = ..., + insertwidth: _ScreenUnits = ..., + invalidcommand: _EntryValidateCommand = ..., + invcmd: _EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + readonlybackground: _Color = ..., + relief: _Relief = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + show: str = ..., + state: Literal["normal", "disabled", "readonly"] = ..., + takefocus: _TakeFocusValue = ..., + textvariable: Variable = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: _EntryValidateCommand = ..., + vcmd: _EntryValidateCommand = ..., + width: int = ..., + xscrollcommand: _XYScrollCommand = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + disabledbackground: _Color = ..., + disabledforeground: _Color = ..., + exportselection: bool = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + insertbackground: _Color = ..., + insertborderwidth: _ScreenUnits = ..., + insertofftime: int = ..., + insertontime: int = ..., + insertwidth: _ScreenUnits = ..., + invalidcommand: _EntryValidateCommand = ..., + invcmd: _EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + readonlybackground: _Color = ..., + relief: _Relief = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + show: str = ..., + state: Literal["normal", "disabled", "readonly"] = ..., + takefocus: _TakeFocusValue = ..., + textvariable: Variable = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: _EntryValidateCommand = ..., + vcmd: _EntryValidateCommand = ..., + width: int = ..., + xscrollcommand: _XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _EntryOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _EntryOptionName) -> Any: ... def delete(self, first, last: Optional[Any] = ...): ... def get(self): ... def icursor(self, index): ... @@ -759,14 +1449,315 @@ class Entry(Widget, XView): def selection_to(self, index): ... select_to: Any +_FrameOptionName = Literal[ + "background", + "bd", + "bg", + "border", + "borderwidth", + "class", + "colormap", + "container", + "cursor", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "padx", + "pady", + "relief", + "takefocus", + "visual", + "width", +] + class Frame(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + class_: str = ..., + colormap: Union[Literal["new", ""], Misc] = ..., + container: bool = ..., + cursor: _Cursor = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + takefocus: _TakeFocusValue = ..., + visual: Union[str, Tuple[str, int]] = ..., + width: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + takefocus: _TakeFocusValue = ..., + width: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _FrameOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _FrameOptionName) -> Any: ... + +_LabelOptionName = Literal[ + "activebackground", + "activeforeground", + "anchor", + "background", + "bd", + "bg", + "bitmap", + "border", + "borderwidth", + "compound", + "cursor", + "disabledforeground", + "fg", + "font", + "foreground", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "image", + "justify", + "padx", + "pady", + "relief", + "state", + "takefocus", + "text", + "textvariable", + "underline", + "width", + "wraplength", +] class Label(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + justify: Literal["left", "center", "right"] = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + underline: int = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + justify: Literal["left", "center", "right"] = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + underline: int = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _LabelOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _LabelOptionName) -> Any: ... + +_ListboxOptionName = Literal[ + "activestyle", + "background", + "bd", + "bg", + "border", + "borderwidth", + "cursor", + "disabledforeground", + "exportselection", + "fg", + "font", + "foreground", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "justify", + "listvariable", + "relief", + "selectbackground", + "selectborderwidth", + "selectforeground", + "selectmode", + "setgrid", + "state", + "takefocus", + "width", + "xscrollcommand", + "yscrollcommand", +] class Listbox(Widget, XView, YView): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activestyle: Literal["dotbox", "none", "underline"] = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + exportselection: bool = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: int = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + justify: Literal["left", "center", "right"] = ..., + # There's no tkinter.ListVar, but seems like bare tkinter.Variable + # actually works for this: + # + # >>> import tkinter + # >>> lb = tkinter.Listbox() + # >>> var = lb['listvariable'] = tkinter.Variable() + # >>> var.set(['foo', 'bar', 'baz']) + # >>> lb.get(0, 'end') + # ('foo', 'bar', 'baz') + listvariable: Variable = ..., + relief: _Relief = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + # from listbox man page: "The value of the [selectmode] option may be + # arbitrary, but the default bindings expect it to be ..." + # + # I have never seen anyone setting this to something else than what + # "the default bindings expect", but let's support it anyway. + selectmode: str = ..., + setgrid: bool = ..., + state: Literal["normal", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + width: int = ..., + xscrollcommand: _XYScrollCommand = ..., + yscrollcommand: _XYScrollCommand = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activestyle: Literal["dotbox", "none", "underline"] = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + exportselection: bool = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: int = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + justify: Literal["left", "center", "right"] = ..., + listvariable: Variable = ..., + relief: _Relief = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + selectmode: str = ..., + setgrid: bool = ..., + state: Literal["normal", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + width: int = ..., + xscrollcommand: _XYScrollCommand = ..., + yscrollcommand: _XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _ListboxOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _ListboxOptionName) -> Any: ... def activate(self, index): ... def bbox(self, index): ... def curselection(self): ... @@ -791,8 +1782,92 @@ class Listbox(Widget, XView, YView): def itemconfigure(self, index, cnf: Optional[Any] = ..., **kw): ... itemconfig: Any +_MenuOptionName = Literal[ + "activebackground", + "activeborderwidth", + "activeforeground", + "background", + "bd", + "bg", + "border", + "borderwidth", + "cursor", + "disabledforeground", + "fg", + "font", + "foreground", + "postcommand", + "relief", + "selectcolor", + "takefocus", + "tearoff", + "tearoffcommand", + "title", + "type", +] + class Menu(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeborderwidth: _ScreenUnits = ..., + activeforeground: _Color = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + postcommand: Union[Callable[[], None], str] = ..., + relief: _Relief = ..., + selectcolor: _Color = ..., + takefocus: _TakeFocusValue = ..., + tearoff: bool = ..., + # I guess tearoffcommand arguments are supposed to be widget objects, + # but they are widget name strings. Use nametowidget() to handle the + # arguments of tearoffcommand. + tearoffcommand: Union[Callable[[str, str], None], str] = ..., + title: str = ..., + type: Literal["menubar", "tearoff", "normal"] = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeborderwidth: _ScreenUnits = ..., + activeforeground: _Color = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + postcommand: Union[Callable[[], None], str] = ..., + relief: _Relief = ..., + selectcolor: _Color = ..., + takefocus: _TakeFocusValue = ..., + tearoff: bool = ..., + tearoffcommand: Union[Callable[[str, str], None], str] = ..., + title: str = ..., + type: Literal["menubar", "tearoff", "normal"] = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _MenuOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _MenuOptionName) -> Any: ... def tk_popup(self, x, y, entry: str = ...): ... if sys.version_info < (3, 6): def tk_bindForTraversal(self): ... @@ -821,28 +1896,580 @@ class Menu(Widget): def xposition(self, index): ... def yposition(self, index): ... +_MenubuttonOptionName = Literal[ + "activebackground", + "activeforeground", + "anchor", + "background", + "bd", + "bg", + "bitmap", + "border", + "borderwidth", + "compound", + "cursor", + "direction", + "disabledforeground", + "fg", + "font", + "foreground", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "image", + "indicatoron", + "justify", + "menu", + "padx", + "pady", + "relief", + "state", + "takefocus", + "text", + "textvariable", + "underline", + "width", + "wraplength", +] + class Menubutton(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + direction: Literal["above", "below", "left", "right", "flush"] = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + indicatoron: bool = ..., + justify: Literal["left", "center", "right"] = ..., + menu: Menu = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + underline: int = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + direction: Literal["above", "below", "left", "right", "flush"] = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + indicatoron: bool = ..., + justify: Literal["left", "center", "right"] = ..., + menu: Menu = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + underline: int = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _MenubuttonOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _MenubuttonOptionName) -> Any: ... + +_MessageOptionName = Literal[ + "anchor", + "aspect", + "background", + "bd", + "bg", + "border", + "borderwidth", + "cursor", + "fg", + "font", + "foreground", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "justify", + "padx", + "pady", + "relief", + "takefocus", + "text", + "textvariable", + "width", +] class Message(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + anchor: _Anchor = ..., + aspect: int = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + justify: Literal["left", "center", "right"] = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + # there's width but no height + width: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + anchor: _Anchor = ..., + aspect: int = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + justify: Literal["left", "center", "right"] = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + width: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _MessageOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _MessageOptionName) -> Any: ... + +_RadiobuttonOptionName = Literal[ + "activebackground", + "activeforeground", + "anchor", + "background", + "bd", + "bg", + "bitmap", + "border", + "borderwidth", + "command", + "compound", + "cursor", + "disabledforeground", + "fg", + "font", + "foreground", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "image", + "indicatoron", + "justify", + "offrelief", + "overrelief", + "padx", + "pady", + "relief", + "selectcolor", + "selectimage", + "state", + "takefocus", + "text", + "textvariable", + "tristateimage", + "tristatevalue", + "underline", + "value", + "variable", + "width", + "wraplength", +] class Radiobutton(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + command: _ButtonCommand = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + indicatoron: bool = ..., + justify: Literal["left", "center", "right"] = ..., + offrelief: _Relief = ..., + overrelief: _Relief = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + selectcolor: _Color = ..., + selectimage: _ImageSpec = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + tristateimage: _ImageSpec = ..., + tristatevalue: Any = ..., + underline: int = ..., + value: Any = ..., + variable: Union[Variable, Literal[""]] = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activeforeground: _Color = ..., + anchor: _Anchor = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bitmap: _Bitmap = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + command: _ButtonCommand = ..., + compound: _Compound = ..., + cursor: _Cursor = ..., + disabledforeground: _Color = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + image: _ImageSpec = ..., + indicatoron: bool = ..., + justify: Literal["left", "center", "right"] = ..., + offrelief: _Relief = ..., + overrelief: _Relief = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + selectcolor: _Color = ..., + selectimage: _ImageSpec = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + textvariable: Variable = ..., + tristateimage: _ImageSpec = ..., + tristatevalue: Any = ..., + underline: int = ..., + value: Any = ..., + variable: Union[Variable, Literal[""]] = ..., + width: _ScreenUnits = ..., + wraplength: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _RadiobuttonOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _RadiobuttonOptionName) -> Any: ... def deselect(self): ... def flash(self): ... def invoke(self): ... def select(self): ... +_ScaleOptionName = Literal[ + "activebackground", + "background", + "bd", + "bg", + "bigincrement", + "border", + "borderwidth", + "command", + "cursor", + "digits", + "fg", + "font", + "foreground", + "from", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "label", + "length", + "orient", + "relief", + "repeatdelay", + "repeatinterval", + "resolution", + "showvalue", + "sliderlength", + "sliderrelief", + "state", + "takefocus", + "tickinterval", + "to", + "troughcolor", + "variable", + "width", +] + class Scale(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bigincrement: float = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + # don't know why the callback gets string instead of float + command: Union[str, Callable[[str], None]] = ..., + cursor: _Cursor = ..., + digits: int = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + from_: float = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + label: str = ..., + length: _ScreenUnits = ..., + orient: Literal["horizontal", "vertical"] = ..., + relief: _Relief = ..., + repeatdelay: int = ..., + repeatinterval: int = ..., + resolution: float = ..., + showvalue: bool = ..., + sliderlength: _ScreenUnits = ..., + sliderrelief: _Relief = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + tickinterval: float = ..., + to: float = ..., + troughcolor: _Color = ..., + variable: DoubleVar = ..., + width: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + bigincrement: float = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + command: Union[str, Callable[[str], None]] = ..., + cursor: _Cursor = ..., + digits: int = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + from_: float = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + label: str = ..., + length: _ScreenUnits = ..., + orient: Literal["horizontal", "vertical"] = ..., + relief: _Relief = ..., + repeatdelay: int = ..., + repeatinterval: int = ..., + resolution: float = ..., + showvalue: bool = ..., + sliderlength: _ScreenUnits = ..., + sliderrelief: _Relief = ..., + state: Literal["normal", "active", "disabled"] = ..., + takefocus: _TakeFocusValue = ..., + tickinterval: float = ..., + to: float = ..., + troughcolor: _Color = ..., + variable: DoubleVar = ..., + width: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _ScaleOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _ScaleOptionName) -> Any: ... def get(self): ... def set(self, value): ... def coords(self, value: Optional[Any] = ...): ... def identify(self, x, y): ... +_ScrollbarOptionName = Literal[ + "activebackground", + "activerelief", + "background", + "bd", + "bg", + "border", + "borderwidth", + "command", + "cursor", + "elementborderwidth", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "jump", + "orient", + "relief", + "repeatdelay", + "repeatinterval", + "takefocus", + "troughcolor", + "width", +] + class Scrollbar(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activerelief: _Relief = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + # There are many ways how the command may get called. Search for + # 'SCROLLING COMMANDS' in scrollbar man page. There doesn't seem to + # be any way to specify an overloaded callback function, so we say + # that it can take any args while it can't in reality. + command: Union[Callable[..., Optional[Tuple[float, float]]], str] = ..., + cursor: _Cursor = ..., + elementborderwidth: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + jump: bool = ..., + orient: Literal["horizontal", "vertical"] = ..., + relief: _Relief = ..., + repeatdelay: int = ..., + repeatinterval: int = ..., + takefocus: _TakeFocusValue = ..., + troughcolor: _Color = ..., + width: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + activerelief: _Relief = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + command: Union[Callable[..., Optional[Tuple[float, float]]], str] = ..., + cursor: _Cursor = ..., + elementborderwidth: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + jump: bool = ..., + orient: Literal["horizontal", "vertical"] = ..., + relief: _Relief = ..., + repeatdelay: int = ..., + repeatinterval: int = ..., + takefocus: _TakeFocusValue = ..., + troughcolor: _Color = ..., + width: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _ScrollbarOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _ScrollbarOptionName) -> Any: ... def activate(self, index: Optional[Any] = ...): ... def delta(self, deltax, deltay): ... def fraction(self, x, y): ... @@ -850,8 +2477,165 @@ class Scrollbar(Widget): def get(self): ... def set(self, first, last): ... +_TextOptionName = Literal[ + "autoseparators", + "background", + "bd", + "bg", + "blockcursor", + "border", + "borderwidth", + "cursor", + "endline", + "exportselection", + "fg", + "font", + "foreground", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "inactiveselectbackground", + "insertbackground", + "insertborderwidth", + "insertofftime", + "insertontime", + "insertunfocussed", + "insertwidth", + "maxundo", + "padx", + "pady", + "relief", + "selectbackground", + "selectborderwidth", + "selectforeground", + "setgrid", + "spacing1", + "spacing2", + "spacing3", + "startline", + "state", + "tabs", + "tabstyle", + "takefocus", + "undo", + "width", + "wrap", + "xscrollcommand", + "yscrollcommand", +] + class Text(Widget, XView, YView): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + autoseparators: bool = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + blockcursor: bool = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + endline: Union[int, Literal[""]] = ..., + exportselection: bool = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + # width is always int, but height is allowed to be ScreenUnits. + # This doesn't make any sense to me, and this isn't documented. + # The docs seem to say that both should be integers. + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + inactiveselectbackground: _Color = ..., + insertbackground: _Color = ..., + insertborderwidth: _ScreenUnits = ..., + insertofftime: int = ..., + insertontime: int = ..., + insertunfocussed: Literal["none", "hollow", "solid"] = ..., + insertwidth: _ScreenUnits = ..., + maxundo: int = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + setgrid: bool = ..., + spacing1: _ScreenUnits = ..., + spacing2: _ScreenUnits = ..., + spacing3: _ScreenUnits = ..., + startline: Union[int, Literal[""]] = ..., + state: Literal["normal", "disabled"] = ..., + # Literal inside Tuple doesn't actually work + tabs: Union[_ScreenUnits, str, Tuple[Union[_ScreenUnits, str], ...]] = ..., + tabstyle: Literal["tabular", "wordprocessor"] = ..., + takefocus: _TakeFocusValue = ..., + undo: bool = ..., + width: int = ..., + wrap: Literal["none", "char", "word"] = ..., + xscrollcommand: _XYScrollCommand = ..., + yscrollcommand: _XYScrollCommand = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + autoseparators: bool = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + blockcursor: bool = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + endline: Union[int, Literal[""]] = ..., + exportselection: bool = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + inactiveselectbackground: _Color = ..., + insertbackground: _Color = ..., + insertborderwidth: _ScreenUnits = ..., + insertofftime: int = ..., + insertontime: int = ..., + insertunfocussed: Literal["none", "hollow", "solid"] = ..., + insertwidth: _ScreenUnits = ..., + maxundo: int = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + setgrid: bool = ..., + spacing1: _ScreenUnits = ..., + spacing2: _ScreenUnits = ..., + spacing3: _ScreenUnits = ..., + startline: Union[int, Literal[""]] = ..., + state: Literal["normal", "disabled"] = ..., + tabs: Union[_ScreenUnits, str, Tuple[Union[_ScreenUnits, str], ...]] = ..., + tabstyle: Literal["tabular", "wordprocessor"] = ..., + takefocus: _TakeFocusValue = ..., + undo: bool = ..., + width: int = ..., + wrap: Literal["none", "char", "word"] = ..., + xscrollcommand: _XYScrollCommand = ..., + yscrollcommand: _XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _TextOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _TextOptionName) -> Any: ... def bbox(self, index): ... def compare(self, index1, op, index2): ... def count(self, index1, index2, *args): ... @@ -932,12 +2716,22 @@ class _setit: def __init__(self, var, value, callback: Optional[Any] = ...): ... def __call__(self, *args): ... +# manual page: tk_optionMenu class OptionMenu(Menubutton): widgetName: Any menuname: Any - def __init__(self, master, variable, value, *values, **kwargs): ... - def __getitem__(self, name): ... - def destroy(self): ... + def __init__( + # differs from other widgets + self, + master: Optional[Misc], + variable: StringVar, + value: str, + *values: str, + # kwarg only from now on + command: Optional[Callable[[StringVar], None]] = ..., + ) -> None: ... + # configure, config, cget are inherited from Menubutton + # destroy and __getitem__ are overrided, signature does not change class Image: name: Any @@ -975,8 +2769,177 @@ class BitmapImage(Image): def image_names(): ... def image_types(): ... +_SpinboxOptionName = Literal[ + "activebackground", + "background", + "bd", + "bg", + "border", + "borderwidth", + "buttonbackground", + "buttoncursor", + "buttondownrelief", + "buttonuprelief", + "command", + "cursor", + "disabledbackground", + "disabledforeground", + "exportselection", + "fg", + "font", + "foreground", + "format", + "from", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "increment", + "insertbackground", + "insertborderwidth", + "insertofftime", + "insertontime", + "insertwidth", + "invalidcommand", + "invcmd", + "justify", + "readonlybackground", + "relief", + "repeatdelay", + "repeatinterval", + "selectbackground", + "selectborderwidth", + "selectforeground", + "state", + "takefocus", + "textvariable", + "to", + "validate", + "validatecommand", + "vcmd", + "values", + "width", + "wrap", + "xscrollcommand", +] + class Spinbox(Widget, XView): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + buttonbackground: _Color = ..., + buttoncursor: _Cursor = ..., + buttondownrelief: _Relief = ..., + buttonuprelief: _Relief = ..., + # percent substitutions don't seem to be supported, it's similar to Entry's validion stuff + command: Union[Callable[[], None], str, _TkinterSequence[str]] = ..., + cursor: _Cursor = ..., + disabledbackground: _Color = ..., + disabledforeground: _Color = ..., + exportselection: bool = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + format: str = ..., + from_: float = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + increment: float = ..., + insertbackground: _Color = ..., + insertborderwidth: _ScreenUnits = ..., + insertofftime: int = ..., + insertontime: int = ..., + insertwidth: _ScreenUnits = ..., + invalidcommand: _EntryValidateCommand = ..., + invcmd: _EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + readonlybackground: _Color = ..., + relief: _Relief = ..., + repeatdelay: int = ..., + repeatinterval: int = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + state: Literal["normal", "disabled", "readonly"] = ..., + takefocus: _TakeFocusValue = ..., + textvariable: Variable = ..., + to: float = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: _EntryValidateCommand = ..., + vcmd: _EntryValidateCommand = ..., + values: _TkinterSequence[str] = ..., + width: int = ..., + wrap: bool = ..., + xscrollcommand: _XYScrollCommand = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + activebackground: _Color = ..., + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + buttonbackground: _Color = ..., + buttoncursor: _Cursor = ..., + buttondownrelief: _Relief = ..., + buttonuprelief: _Relief = ..., + command: Union[Callable[[], None], str, _TkinterSequence[str]] = ..., + cursor: _Cursor = ..., + disabledbackground: _Color = ..., + disabledforeground: _Color = ..., + exportselection: bool = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + format: str = ..., + from_: float = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + increment: float = ..., + insertbackground: _Color = ..., + insertborderwidth: _ScreenUnits = ..., + insertofftime: int = ..., + insertontime: int = ..., + insertwidth: _ScreenUnits = ..., + invalidcommand: _EntryValidateCommand = ..., + invcmd: _EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + readonlybackground: _Color = ..., + relief: _Relief = ..., + repeatdelay: int = ..., + repeatinterval: int = ..., + selectbackground: _Color = ..., + selectborderwidth: _ScreenUnits = ..., + selectforeground: _Color = ..., + state: Literal["normal", "disabled", "readonly"] = ..., + takefocus: _TakeFocusValue = ..., + textvariable: Variable = ..., + to: float = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: _EntryValidateCommand = ..., + vcmd: _EntryValidateCommand = ..., + values: _TkinterSequence[str] = ..., + width: int = ..., + wrap: bool = ..., + xscrollcommand: _XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _SpinboxOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _SpinboxOptionName) -> Any: ... def bbox(self, index): ... def delete(self, first, last: Optional[Any] = ...): ... def get(self): ... @@ -998,11 +2961,182 @@ class Spinbox(Widget, XView): def selection_range(self, start: int, end: int) -> None: ... def selection_to(self, index: int) -> None: ... +_LabelFrameOptionName = Literal[ + "background", + "bd", + "bg", + "border", + "borderwidth", + "class", + "colormap", + "container", + "cursor", + "fg", + "font", + "foreground", + "height", + "highlightbackground", + "highlightcolor", + "highlightthickness", + "labelanchor", + "labelwidget", + "padx", + "pady", + "relief", + "takefocus", + "text", + "visual", + "width", +] + class LabelFrame(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + class_: str = ..., + colormap: Union[Literal["new", ""], Misc] = ..., + container: bool = ..., # undocumented + cursor: _Cursor = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + # 'ne' and 'en' are valid labelanchors, but only 'ne' is a valid _Anchor. + labelanchor: Literal["nw", "n", "ne", "en", "e", "es", "se", "s", "sw", "ws", "w", "wn"] = ..., + labelwidget: Misc = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + visual: Union[str, Tuple[str, int]] = ..., + width: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + fg: _Color = ..., + font: _FontDescription = ..., + foreground: _Color = ..., + height: _ScreenUnits = ..., + highlightbackground: _Color = ..., + highlightcolor: _Color = ..., + highlightthickness: _ScreenUnits = ..., + labelanchor: Literal["nw", "n", "ne", "en", "e", "es", "se", "s", "sw", "ws", "w", "wn"] = ..., + labelwidget: Misc = ..., + padx: _ScreenUnits = ..., + pady: _ScreenUnits = ..., + relief: _Relief = ..., + takefocus: _TakeFocusValue = ..., + text: str = ..., + width: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _LabelFrameOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _LabelFrameOptionName) -> Any: ... + +_PanedWindowOptionName = Literal[ + "background", + "bd", + "bg", + "border", + "borderwidth", + "cursor", + "handlepad", + "handlesize", + "height", + "opaqueresize", + "orient", + "proxybackground", + "proxyborderwidth", + "proxyrelief", + "relief", + "sashcursor", + "sashpad", + "sashrelief", + "sashwidth", + "showhandle", + "width", +] class PanedWindow(Widget): - def __init__(self, master: Optional[Any] = ..., cnf=..., **kw): ... + def __init__( + self, + master: Optional[Misc] = ..., + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + handlepad: _ScreenUnits = ..., + handlesize: _ScreenUnits = ..., + height: _ScreenUnits = ..., + opaqueresize: bool = ..., + orient: Literal["horizontal", "vertical"] = ..., + proxybackground: _Color = ..., + proxyborderwidth: _ScreenUnits = ..., + proxyrelief: _Relief = ..., + relief: _Relief = ..., + sashcursor: _Cursor = ..., + sashpad: _ScreenUnits = ..., + sashrelief: _Relief = ..., + sashwidth: _ScreenUnits = ..., + showhandle: bool = ..., + width: _ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: _Color = ..., + bd: _ScreenUnits = ..., + bg: _Color = ..., + border: _ScreenUnits = ..., + borderwidth: _ScreenUnits = ..., + cursor: _Cursor = ..., + handlepad: _ScreenUnits = ..., + handlesize: _ScreenUnits = ..., + height: _ScreenUnits = ..., + opaqueresize: bool = ..., + orient: Literal["horizontal", "vertical"] = ..., + proxybackground: _Color = ..., + proxyborderwidth: _ScreenUnits = ..., + proxyrelief: _Relief = ..., + relief: _Relief = ..., + sashcursor: _Cursor = ..., + sashpad: _ScreenUnits = ..., + sashrelief: _Relief = ..., + sashwidth: _ScreenUnits = ..., + showhandle: bool = ..., + width: _ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _PanedWindowOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _PanedWindowOptionName) -> Any: ... def add(self, child, **kw): ... def remove(self, child): ... forget: Any diff --git a/stdlib/3/tkinter/font.pyi b/stdlib/3/tkinter/font.pyi index 0bdee0fe6246..b884d9d51c33 100644 --- a/stdlib/3/tkinter/font.pyi +++ b/stdlib/3/tkinter/font.pyi @@ -9,21 +9,10 @@ ITALIC: Literal["italic"] def nametofont(name: str) -> Font: ... -# _TkinterSequence[T] represents a sequence that tkinter understands. It -# differs from typing.Sequence[T]. For example, collections.deque a valid -# Sequence but not a valid _TkinterSequence: -# -# >>> tkinter.Label(font=('Helvetica', 12, collections.deque(['bold']))) -# Traceback (most recent call last): -# ... -# _tkinter.TclError: unknown font style "deque(['bold'])" -_T = TypeVar("_T") -_TkinterSequence = Union[List[_T], Tuple[_T, ...]] - # See 'FONT DESCRIPTIONS' in font man page. This uses str because Literal # inside Tuple doesn't work. _FontDescription = Union[ - str, Font, Tuple[str, int], Tuple[str, int, str], Tuple[str, int, _TkinterSequence[str]], + str, Font, Tuple[str, int], Tuple[str, int, str], Tuple[str, int, tkinter._TkinterSequence[str]], ] class _FontDict(TypedDict): diff --git a/stdlib/3/tkinter/ttk.pyi b/stdlib/3/tkinter/ttk.pyi index 23af5ada9abc..564ddae3abc1 100644 --- a/stdlib/3/tkinter/ttk.pyi +++ b/stdlib/3/tkinter/ttk.pyi @@ -1,12 +1,16 @@ import _tkinter import sys import tkinter -from typing import Any, Callable, List, Optional, overload +from tkinter.font import _FontDescription +from typing import Any, Callable, Dict, List, Optional, Tuple, Union, overload from typing_extensions import Literal def tclobjs_to_py(adict): ... def setup_master(master: Optional[Any] = ...): ... +# from ttk_widget (aka ttk::widget) manual page, differs from tkinter._Compound +_TtkCompound = Literal["text", "image", tkinter._Compound] + class Style: master: Any tk: _tkinter.TkappType @@ -24,46 +28,576 @@ class Style: def theme_use(self, themename: Optional[Any] = ...): ... class Widget(tkinter.Widget): - def __init__(self, master, widgetname, kw: Optional[Any] = ...): ... + def __init__(self, master: Optional[tkinter.Misc], widgetname, kw: Optional[Any] = ...): ... def identify(self, x, y): ... def instate(self, statespec, callback: Optional[Any] = ..., *args, **kw): ... def state(self, statespec: Optional[Any] = ...): ... +_ButtonOptionName = Literal[ + "class", + "command", + "compound", + "cursor", + "default", + "image", + "padding", + "state", + "style", + "takefocus", + "text", + "textvariable", + "underline", + "width", +] + class Button(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + command: tkinter._ButtonCommand = ..., + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + default: Literal["normal", "active", "disabled"] = ..., + image: tkinter._ImageSpec = ..., + padding: Any = ..., # undocumented + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + width: Union[int, Literal[""]] = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + command: tkinter._ButtonCommand = ..., + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + default: Literal["normal", "active", "disabled"] = ..., + image: tkinter._ImageSpec = ..., + padding: Any = ..., + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + width: Union[int, Literal[""]] = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _ButtonOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _ButtonOptionName) -> Any: ... def invoke(self): ... +_CheckbuttonOptionName = Literal[ + "class", + "command", + "compound", + "cursor", + "image", + "offvalue", + "onvalue", + "padding", + "state", + "style", + "takefocus", + "text", + "textvariable", + "underline", + "variable", + "width", +] + class Checkbutton(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + command: tkinter._ButtonCommand = ..., + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + image: tkinter._ImageSpec = ..., + offvalue: Any = ..., + onvalue: Any = ..., + padding: Any = ..., # undocumented + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + # Seems like variable can be empty string, but actually setting it to + # empty string segfaults before Tcl 8.6.9. Search for ttk::checkbutton + # here: https://sourceforge.net/projects/tcl/files/Tcl/8.6.9/tcltk-release-notes-8.6.9.txt/view + variable: tkinter.Variable = ..., + width: Union[int, Literal[""]] = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + command: tkinter._ButtonCommand = ..., + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + image: tkinter._ImageSpec = ..., + offvalue: Any = ..., + onvalue: Any = ..., + padding: Any = ..., + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + variable: tkinter.Variable = ..., + width: Union[int, Literal[""]] = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _CheckbuttonOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _CheckbuttonOptionName) -> Any: ... def invoke(self): ... +_EntryOptionName = Literal[ + "background", + "class", + "cursor", + "exportselection", + "font", + "foreground", + "invalidcommand", + "justify", + "show", + "state", + "style", + "takefocus", + "textvariable", + "validate", + "validatecommand", + "width", + "xscrollcommand", +] + class Entry(Widget, tkinter.Entry): - def __init__(self, master: Optional[Any] = ..., widget: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + widget: Optional[str] = ..., + *, + background: tkinter._Color = ..., # undocumented + class_: str = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., + font: _FontDescription = ..., + foreground: tkinter._Color = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + show: str = ..., + state: Literal["normal", "disabled", "readonly"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: tkinter._EntryValidateCommand = ..., + width: int = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + ) -> None: ... + @overload # type: ignore + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: tkinter._Color = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., + font: _FontDescription = ..., + foreground: tkinter._Color = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + show: str = ..., + state: Literal["normal", "disabled", "readonly"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: tkinter._EntryValidateCommand = ..., + width: int = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _EntryOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure # type: ignore + def cget(self, key: _EntryOptionName) -> Any: ... # type: ignore def bbox(self, index): ... def identify(self, x, y): ... def validate(self): ... +_ComboboxOptionName = Literal[ + "background", + "class", + "cursor", + "exportselection", + "font", + "foreground", + "height", + "invalidcommand", + "justify", + "postcommand", + "show", + "state", + "style", + "takefocus", + "textvariable", + "validate", + "validatecommand", + "values", + "width", + "xscrollcommand", +] + class Combobox(Entry): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + background: tkinter._Color = ..., # undocumented + class_: str = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., + font: _FontDescription = ..., # undocumented + foreground: tkinter._Color = ..., # undocumented + height: int = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., # undocumented + justify: Literal["left", "center", "right"] = ..., + postcommand: Union[Callable[[], None], str] = ..., + show: Any = ..., # undocumented + state: Literal["normal", "readonly", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., # undocumented + validatecommand: tkinter._EntryValidateCommand = ..., # undocumented + values: tkinter._TkinterSequence[str] = ..., + width: int = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., # undocumented + ) -> None: ... + @overload # type: ignore + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: tkinter._Color = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., + font: _FontDescription = ..., + foreground: tkinter._Color = ..., + height: int = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + postcommand: Union[Callable[[], None], str] = ..., + show: Any = ..., + state: Literal["normal", "readonly", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: tkinter._EntryValidateCommand = ..., + values: tkinter._TkinterSequence[str] = ..., + width: int = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _ComboboxOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure # type: ignore + def cget(self, key: _ComboboxOptionName) -> Any: ... # type: ignore def current(self, newindex: Optional[Any] = ...): ... def set(self, value): ... +_FrameOptionName = Literal[ + "border", "borderwidth", "class", "cursor", "height", "padding", "relief", "style", "takefocus", "width" +] + class Frame(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + border: tkinter._ScreenUnits = ..., + borderwidth: tkinter._ScreenUnits = ..., + class_: str = ..., + cursor: tkinter._Cursor = ..., + height: tkinter._ScreenUnits = ..., + padding: tkinter._Padding = ..., + relief: tkinter._Relief = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + width: tkinter._ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + border: tkinter._ScreenUnits = ..., + borderwidth: tkinter._ScreenUnits = ..., + cursor: tkinter._Cursor = ..., + height: tkinter._ScreenUnits = ..., + padding: tkinter._Padding = ..., + relief: tkinter._Relief = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + width: tkinter._ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _FrameOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _FrameOptionName) -> Any: ... + +_LabelOptionName = Literal[ + "anchor", + "background", + "border", + "borderwidth", + "class", + "compound", + "cursor", + "font", + "foreground", + "image", + "justify", + "padding", + "relief", + "state", + "style", + "takefocus", + "text", + "textvariable", + "underline", + "width", + "wraplength", +] class Label(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + anchor: tkinter._Anchor = ..., + background: tkinter._Color = ..., + border: tkinter._ScreenUnits = ..., # alias for borderwidth + borderwidth: tkinter._ScreenUnits = ..., # undocumented + class_: str = ..., + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + font: _FontDescription = ..., + foreground: tkinter._Color = ..., + image: tkinter._ImageSpec = ..., + justify: Literal["left", "center", "right"] = ..., + padding: tkinter._Padding = ..., + relief: tkinter._Relief = ..., + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + width: Union[int, Literal[""]] = ..., + wraplength: tkinter._ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + anchor: tkinter._Anchor = ..., + background: tkinter._Color = ..., + border: tkinter._ScreenUnits = ..., + borderwidth: tkinter._ScreenUnits = ..., + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + font: _FontDescription = ..., + foreground: tkinter._Color = ..., + image: tkinter._ImageSpec = ..., + justify: Literal["left", "center", "right"] = ..., + padding: tkinter._Padding = ..., + relief: tkinter._Relief = ..., + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + width: Union[int, Literal[""]] = ..., + wraplength: tkinter._ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _LabelOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _LabelOptionName) -> Any: ... + +_LabelframeOptionName = Literal[ + "border", + "borderwidth", + "class", + "cursor", + "height", + "labelanchor", + "labelwidget", + "padding", + "relief", + "style", + "takefocus", + "text", + "underline", + "width", +] class Labelframe(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + border: tkinter._ScreenUnits = ..., + borderwidth: tkinter._ScreenUnits = ..., # undocumented + class_: str = ..., + cursor: tkinter._Cursor = ..., + height: tkinter._ScreenUnits = ..., + labelanchor: Literal["nw", "n", "ne", "en", "e", "es", "se", "s", "sw", "ws", "w", "wn"] = ..., + labelwidget: tkinter.Misc = ..., + padding: tkinter._Padding = ..., + relief: tkinter._Relief = ..., # undocumented + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + underline: int = ..., + width: tkinter._ScreenUnits = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + border: tkinter._ScreenUnits = ..., + borderwidth: tkinter._ScreenUnits = ..., + cursor: tkinter._Cursor = ..., + height: tkinter._ScreenUnits = ..., + labelanchor: Literal["nw", "n", "ne", "en", "e", "es", "se", "s", "sw", "ws", "w", "wn"] = ..., + labelwidget: tkinter.Misc = ..., + padding: tkinter._Padding = ..., + relief: tkinter._Relief = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + underline: int = ..., + width: tkinter._ScreenUnits = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _LabelframeOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _LabelframeOptionName) -> Any: ... + +LabelFrame = Labelframe -LabelFrame: Any +_MenubuttonOptionName = Literal[ + "class", + "compound", + "cursor", + "direction", + "image", + "menu", + "padding", + "state", + "style", + "takefocus", + "text", + "textvariable", + "underline", + "width", +] class Menubutton(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + direction: Literal["above", "below", "left", "right", "flush"] = ..., + image: tkinter._ImageSpec = ..., + menu: tkinter.Menu = ..., + padding: Any = ..., # undocumented + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + width: Union[int, Literal[""]] = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + direction: Literal["above", "below", "left", "right", "flush"] = ..., + image: tkinter._ImageSpec = ..., + menu: tkinter.Menu = ..., + padding: Any = ..., + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + width: Union[int, Literal[""]] = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _MenubuttonOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _MenubuttonOptionName) -> Any: ... + +_NotebookOptionName = Literal["class", "cursor", "height", "padding", "style", "takefocus", "width"] class Notebook(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + cursor: tkinter._Cursor = ..., + height: int = ..., + padding: tkinter._Padding = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + width: int = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + cursor: tkinter._Cursor = ..., + height: int = ..., + padding: tkinter._Padding = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + width: int = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _NotebookOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _NotebookOptionName) -> Any: ... def add(self, child, **kw): ... def forget(self, tab_id): ... def hide(self, tab_id): ... @@ -75,46 +609,433 @@ class Notebook(Widget): def tabs(self): ... def enable_traversal(self): ... +_PanedwindowOptionName = Literal["class", "cursor", "height", "orient", "style", "takefocus", "width"] + class Panedwindow(Widget, tkinter.PanedWindow): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + cursor: tkinter._Cursor = ..., + # width and height for tkinter.ttk.Panedwindow are int but for tkinter.PanedWindow they are screen units + height: int = ..., + orient: Literal["vertical", "horizontal"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + width: int = ..., + ) -> None: ... + @overload # type: ignore + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + cursor: tkinter._Cursor = ..., + height: int = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + width: int = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _PanedwindowOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure # type: ignore + def cget(self, key: _PanedwindowOptionName) -> Any: ... # type: ignore forget: Any def insert(self, pos, child, **kw): ... def pane(self, pane, option: Optional[Any] = ..., **kw): ... def sashpos(self, index, newpos: Optional[Any] = ...): ... -PanedWindow: Any +PanedWindow = Panedwindow + +_ProgressbarOptionName = Literal[ + "class", "cursor", "length", "maximum", "mode", "orient", "phase", "style", "takefocus", "value", "variable" +] class Progressbar(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + cursor: tkinter._Cursor = ..., + length: tkinter._ScreenUnits = ..., + maximum: float = ..., + mode: Literal["determinate", "indeterminate"] = ..., + orient: Literal["horizontal", "vertical"] = ..., + phase: int = ..., # docs say read-only but assigning int to this works + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + value: float = ..., + variable: tkinter.DoubleVar = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + cursor: tkinter._Cursor = ..., + length: tkinter._ScreenUnits = ..., + maximum: float = ..., + mode: Literal["determinate", "indeterminate"] = ..., + orient: Literal["horizontal", "vertical"] = ..., + phase: int = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + value: float = ..., + variable: tkinter.DoubleVar = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _ProgressbarOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _ProgressbarOptionName) -> Any: ... def start(self, interval: Optional[Any] = ...): ... def step(self, amount: Optional[Any] = ...): ... def stop(self): ... +_RadiobuttonOptionName = Literal[ + "class", + "command", + "compound", + "cursor", + "image", + "padding", + "state", + "style", + "takefocus", + "text", + "textvariable", + "underline", + "value", + "variable", + "width", +] + class Radiobutton(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + command: tkinter._ButtonCommand = ..., + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + image: tkinter._ImageSpec = ..., + padding: Any = ..., # undocumented + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + value: Any = ..., + variable: Union[tkinter.Variable, Literal[""]] = ..., + width: Union[int, Literal[""]] = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + command: tkinter._ButtonCommand = ..., + compound: _TtkCompound = ..., + cursor: tkinter._Cursor = ..., + image: tkinter._ImageSpec = ..., + padding: Any = ..., + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + text: str = ..., + textvariable: tkinter.Variable = ..., + underline: int = ..., + value: Any = ..., + variable: Union[tkinter.Variable, Literal[""]] = ..., + width: Union[int, Literal[""]] = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _RadiobuttonOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _RadiobuttonOptionName) -> Any: ... def invoke(self): ... +_ScaleOptionName = Literal[ + "class", "command", "cursor", "from", "length", "orient", "state", "style", "takefocus", "to", "value", "variable" +] + class Scale(Widget, tkinter.Scale): - def __init__(self, master: Optional[Any] = ..., **kw): ... - def configure(self, cnf: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + command: Union[str, Callable[[str], None]] = ..., + cursor: tkinter._Cursor = ..., + from_: float = ..., + length: tkinter._ScreenUnits = ..., + orient: Literal["horizontal", "vertical"] = ..., + state: Any = ..., # undocumented + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + to: float = ..., + value: float = ..., + variable: tkinter.DoubleVar = ..., + ) -> None: ... + @overload # type: ignore + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + command: Union[str, Callable[[str], None]] = ..., + cursor: tkinter._Cursor = ..., + from_: float = ..., + length: tkinter._ScreenUnits = ..., + orient: Literal["horizontal", "vertical"] = ..., + state: Any = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + to: float = ..., + value: float = ..., + variable: tkinter.DoubleVar = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _ScaleOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure # type: ignore + def cget(self, key: _ScaleOptionName) -> Any: ... # type: ignore def get(self, x: Optional[Any] = ..., y: Optional[Any] = ...): ... +_ScrollbarOptionName = Literal["class", "command", "cursor", "orient", "style", "takefocus"] + class Scrollbar(Widget, tkinter.Scrollbar): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + command: Union[Callable[..., Optional[Tuple[float, float]]], str] = ..., + cursor: tkinter._Cursor = ..., + orient: Literal["horizontal", "vertical"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + ) -> None: ... + @overload # type: ignore + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + command: Union[Callable[..., Optional[Tuple[float, float]]], str] = ..., + cursor: tkinter._Cursor = ..., + orient: Literal["horizontal", "vertical"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _ScrollbarOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure # type: ignore + def cget(self, key: _ScrollbarOptionName) -> Any: ... # type: ignore + +_SeparatorOptionName = Literal["class", "cursor", "orient", "style", "takefocus"] class Separator(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + cursor: tkinter._Cursor = ..., + orient: Literal["horizontal", "vertical"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + cursor: tkinter._Cursor = ..., + orient: Literal["horizontal", "vertical"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _SeparatorOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _SeparatorOptionName) -> Any: ... + +_SizegripOptionName = Literal["class", "cursor", "style", "takefocus"] class Sizegrip(Widget): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + cursor: tkinter._Cursor = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + cursor: tkinter._Cursor = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _SizegripOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _SizegripOptionName) -> Any: ... if sys.version_info >= (3, 7): + _SpinboxOptionName = Literal[ + "background", + "class", + "command", + "cursor", + "exportselection", + "font", + "foreground", + "format", + "from", + "increment", + "invalidcommand", + "justify", + "show", + "state", + "style", + "takefocus", + "textvariable", + "to", + "validate", + "validatecommand", + "values", + "width", + "wrap", + "xscrollcommand", + ] class Spinbox(Entry): - def __init__(self, master: Any = ..., **kw: Any) -> None: ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + background: tkinter._Color = ..., # undocumented + class_: str = ..., + command: Union[Callable[[], None], str, tkinter._TkinterSequence[str]] = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., # undocumented + font: _FontDescription = ..., # undocumented + foreground: tkinter._Color = ..., # undocumented + format: str = ..., + from_: float = ..., + increment: float = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., # undocumented + justify: Literal["left", "center", "right"] = ..., # undocumented + show: Any = ..., # undocumented + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., # undocumented + to: float = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: tkinter._EntryValidateCommand = ..., + values: tkinter._TkinterSequence[str] = ..., + width: int = ..., # undocumented + wrap: bool = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + ) -> None: ... + @overload # type: ignore + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + background: tkinter._Color = ..., + command: Union[Callable[[], None], str, tkinter._TkinterSequence[str]] = ..., + cursor: tkinter._Cursor = ..., + exportselection: bool = ..., + font: _FontDescription = ..., + foreground: tkinter._Color = ..., + format: str = ..., + from_: float = ..., + increment: float = ..., + invalidcommand: tkinter._EntryValidateCommand = ..., + justify: Literal["left", "center", "right"] = ..., + show: Any = ..., + state: Literal["normal", "disabled"] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + textvariable: tkinter.Variable = ..., + to: float = ..., + validate: Literal["none", "focus", "focusin", "focusout", "key", "all"] = ..., + validatecommand: tkinter._EntryValidateCommand = ..., + values: tkinter._TkinterSequence[str] = ..., + width: int = ..., + wrap: bool = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _SpinboxOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure # type: ignore + def cget(self, key: _SpinboxOptionName) -> Any: ... # type: ignore def set(self, value: Any) -> None: ... +_TreeviewOptionName = Literal[ + "class", + "columns", + "cursor", + "displaycolumns", + "height", + "padding", + "selectmode", + "show", + "style", + "takefocus", + "xscrollcommand", + "yscrollcommand", +] + class Treeview(Widget, tkinter.XView, tkinter.YView): - def __init__(self, master: Optional[Any] = ..., **kw): ... + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + *, + class_: str = ..., + columns: Union[str, tkinter._TkinterSequence[str]] = ..., + cursor: tkinter._Cursor = ..., + displaycolumns: Union[str, tkinter._TkinterSequence[str], tkinter._TkinterSequence[int], Literal["#all"]] = ..., + height: int = ..., + padding: tkinter._Padding = ..., + selectmode: Literal["extended", "browse", "none"] = ..., + # _TkinterSequences of Literal don't actually work, using str instead. + # + # 'tree headings' is same as ['tree', 'headings'], and I wouldn't be + # surprised if someone was using it. + show: Union[Literal["tree", "headings", "tree headings"], tkinter._TkinterSequence[str]] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + yscrollcommand: tkinter._XYScrollCommand = ..., + ) -> None: ... + @overload + def configure( + self, + cnf: Optional[Dict[str, Any]] = ..., + *, + columns: Union[str, tkinter._TkinterSequence[str]] = ..., + cursor: tkinter._Cursor = ..., + displaycolumns: Union[str, tkinter._TkinterSequence[str], tkinter._TkinterSequence[int], Literal["#all"]] = ..., + height: int = ..., + padding: tkinter._Padding = ..., + selectmode: Literal["extended", "browse", "none"] = ..., + show: Union[Literal["tree", "headings", "tree headings"], tkinter._TkinterSequence[str]] = ..., + style: str = ..., + takefocus: tkinter._TakeFocusValue = ..., + xscrollcommand: tkinter._XYScrollCommand = ..., + yscrollcommand: tkinter._XYScrollCommand = ..., + ) -> Optional[Dict[str, Tuple[str, str, str, Any, Any]]]: ... + @overload + def configure(self, cnf: _TreeviewOptionName) -> Tuple[str, str, str, Any, Any]: ... + config = configure + def cget(self, key: _TreeviewOptionName) -> Any: ... def bbox(self, item, column: Optional[Any] = ...): ... def get_children(self, item: Optional[Any] = ...): ... def set_children(self, item, *newchildren): ... @@ -166,12 +1087,32 @@ class Treeview(Widget, tkinter.XView, tkinter.YView): class LabeledScale(Frame): label: Any scale: Any - def __init__(self, master: Optional[Any] = ..., variable: Optional[Any] = ..., from_: int = ..., to: int = ..., **kw): ... - def destroy(self): ... + # TODO: don't any-type **kw. That goes to Frame.__init__. + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + variable: Optional[Union[tkinter.IntVar, tkinter.DoubleVar]] = ..., + from_: float = ..., + to: float = ..., + *, + compound: Union[Literal["top"], Literal["bottom"]] = ..., + **kw: Any, + ) -> None: ... + # destroy is overrided, signature does not change value: Any class OptionMenu(Menubutton): - def __init__(self, master, variable, default: Optional[Any] = ..., *values, **kwargs): ... - def __getitem__(self, item): ... + def __init__( + self, + master, + variable, + default: Optional[str] = ..., + *values: str, + # rest of these are keyword-only because *args syntax used above + style: str = ..., + direction: Union[Literal["above"], Literal["below"], Literal["left"], Literal["right"], Literal["flush"]] = ..., + command: Optional[Callable[[tkinter.StringVar], None]] = ..., + ) -> None: ... + # configure, config, cget, destroy are inherited from Menubutton + # destroy and __setitem__ are overrided, signature does not change def set_menu(self, default: Optional[Any] = ..., *values): ... - def destroy(self): ... diff --git a/tests/pytype_exclude_list.txt b/tests/pytype_exclude_list.txt index 00f4ea263d5c..23b922ab5767 100644 --- a/tests/pytype_exclude_list.txt +++ b/tests/pytype_exclude_list.txt @@ -18,7 +18,9 @@ third_party/2and3/pynamodb/models.pyi third_party/3/six/__init__.pyi third_party/3/six/moves/__init__.pyi -# anything that imports tkinter (https://github.com/google/pytype/issues/637) +# anything that imports tkinter +# https://github.com/google/pytype/issues/637 +# https://github.com/google/pytype/issues/644 stdlib/3/tkinter/__init__.pyi stdlib/3/tkinter/dialog.pyi stdlib/3/tkinter/filedialog.pyi