Skip to content

Commit 3c872ca

Browse files
TeamSpen210Akuli
andauthored
Add types to some tkinter.Text methods. (#10946)
Co-authored-by: Akuli <[email protected]>
1 parent a5d6163 commit 3c872ca

File tree

1 file changed

+72
-10
lines changed

1 file changed

+72
-10
lines changed

stdlib/tkinter/__init__.pyi

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,11 +3064,40 @@ class Text(Widget, XView, YView):
30643064
def edit_separator(self) -> None: ... # actually returns empty string
30653065
def edit_undo(self) -> None: ... # actually returns empty string
30663066
def get(self, index1: _TextIndex, index2: _TextIndex | None = None) -> str: ...
3067-
# TODO: image_* methods
3068-
def image_cget(self, index, option): ...
3069-
def image_configure(self, index, cnf: Incomplete | None = None, **kw): ...
3070-
def image_create(self, index, cnf={}, **kw): ...
3071-
def image_names(self): ...
3067+
@overload
3068+
def image_cget(self, index: _TextIndex, option: Literal["image", "name"]) -> str: ...
3069+
@overload
3070+
def image_cget(self, index: _TextIndex, option: Literal["padx", "pady"]) -> int: ...
3071+
@overload
3072+
def image_cget(self, index: _TextIndex, option: Literal["align"]) -> Literal["baseline", "bottom", "center", "top"]: ...
3073+
@overload
3074+
def image_cget(self, index: _TextIndex, option: str) -> Any: ...
3075+
@overload
3076+
def image_configure(self, index: _TextIndex, cnf: str) -> tuple[str, str, str, str, str | int]: ...
3077+
@overload
3078+
def image_configure(
3079+
self,
3080+
index: _TextIndex,
3081+
cnf: dict[str, Any] | None = {},
3082+
*,
3083+
align: Literal["baseline", "bottom", "center", "top"] = ...,
3084+
image: _ImageSpec = ...,
3085+
name: str = ...,
3086+
padx: _ScreenUnits = ...,
3087+
pady: _ScreenUnits = ...,
3088+
) -> dict[str, tuple[str, str, str, str, str | int]] | None: ...
3089+
def image_create(
3090+
self,
3091+
index: _TextIndex,
3092+
cnf: dict[str, Any] | None = {},
3093+
*,
3094+
align: Literal["baseline", "bottom", "center", "top"] = ...,
3095+
image: _ImageSpec = ...,
3096+
name: str = ...,
3097+
padx: _ScreenUnits = ...,
3098+
pady: _ScreenUnits = ...,
3099+
) -> str: ...
3100+
def image_names(self) -> tuple[str, ...]: ...
30723101
def index(self, index: _TextIndex) -> str: ...
30733102
def insert(self, index: _TextIndex, chars: str, *args: str | list[str] | tuple[str, ...]) -> None: ...
30743103
@overload
@@ -3166,12 +3195,45 @@ class Text(Widget, XView, YView):
31663195
def tag_ranges(self, tagName: str) -> tuple[_tkinter.Tcl_Obj, ...]: ...
31673196
# tag_remove and tag_delete are different
31683197
def tag_remove(self, tagName: str, index1: _TextIndex, index2: _TextIndex | None = None) -> None: ...
3169-
# TODO: window_* methods
3170-
def window_cget(self, index, option): ...
3171-
def window_configure(self, index, cnf: Incomplete | None = None, **kw): ...
3198+
@overload
3199+
def window_cget(self, index: _TextIndex, option: Literal["padx", "pady"]) -> int: ...
3200+
@overload
3201+
def window_cget(self, index: _TextIndex, option: Literal["stretch"]) -> bool: ... # actually returns Literal[0, 1]
3202+
@overload
3203+
def window_cget(self, index: _TextIndex, option: Literal["align"]) -> Literal["baseline", "bottom", "center", "top"]: ...
3204+
@overload # window is set to a widget, but read as the string name.
3205+
def window_cget(self, index: _TextIndex, option: Literal["create", "window"]) -> str: ...
3206+
@overload
3207+
def window_cget(self, index: _TextIndex, option: str) -> Any: ...
3208+
@overload
3209+
def window_configure(self, index: _TextIndex, cnf: str) -> tuple[str, str, str, str, str | int]: ...
3210+
@overload
3211+
def window_configure(
3212+
self,
3213+
index: _TextIndex,
3214+
cnf: dict[str, Any] | None = None,
3215+
*,
3216+
align: Literal["baseline", "bottom", "center", "top"] = ...,
3217+
create: str = ...,
3218+
padx: _ScreenUnits = ...,
3219+
pady: _ScreenUnits = ...,
3220+
stretch: bool | Literal[0, 1] = ...,
3221+
window: Misc | str = ...,
3222+
) -> dict[str, tuple[str, str, str, str, str | int]] | None: ...
31723223
window_config = window_configure
3173-
def window_create(self, index, cnf={}, **kw) -> None: ...
3174-
def window_names(self): ...
3224+
def window_create(
3225+
self,
3226+
index: _TextIndex,
3227+
cnf: dict[str, Any] | None = {},
3228+
*,
3229+
align: Literal["baseline", "bottom", "center", "top"] = ...,
3230+
create: str = ...,
3231+
padx: _ScreenUnits = ...,
3232+
pady: _ScreenUnits = ...,
3233+
stretch: bool | Literal[0, 1] = ...,
3234+
window: Misc | str = ...,
3235+
) -> None: ...
3236+
def window_names(self) -> tuple[str, ...]: ...
31753237
def yview_pickplace(self, *what): ... # deprecated
31763238

31773239
class _setit:

0 commit comments

Comments
 (0)