Skip to content

Add missing tkinter submodules #4558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jan 23, 2021
Merged
7 changes: 7 additions & 0 deletions stdlib/2and3/_typeshed/tkinter.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import sys
from typing import Optional, Protocol

if sys.version_info >= (3,):
from tkinter import Event, Misc, Widget
class DndSource(Protocol):
def dnd_end(self, target: Optional[Widget], event: Optional[Event[Misc]]) -> None: ...
20 changes: 11 additions & 9 deletions stdlib/3/_tkinter.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any, Tuple, Union
from typing_extensions import Literal

# _tkinter is meant to be only used internally by tkinter, but some tkinter
# functions e.g. return _tkinter.Tcl_Obj objects. Tcl_Obj represents a Tcl
Expand Down Expand Up @@ -71,16 +72,17 @@ class TkappType:
wantobjects: Any
willdispatch: Any

ALL_EVENTS: int
FILE_EVENTS: int
IDLE_EVENTS: int
TIMER_EVENTS: int
WINDOW_EVENTS: int
# These should be kept in sync with tkinter.tix constants, except ALL_EVENTS which doesn't match TCL_ALL_EVENTS
ALL_EVENTS: Literal[-3]
FILE_EVENTS: Literal[8]
IDLE_EVENTS: Literal[32]
TIMER_EVENTS: Literal[16]
WINDOW_EVENTS: Literal[4]

DONT_WAIT: int
EXCEPTION: int
READABLE: int
WRITABLE: int
DONT_WAIT: Literal[2]
EXCEPTION: Literal[8]
READABLE: Literal[2]
WRITABLE: Literal[4]

TCL_VERSION: str
TK_VERSION: str
Expand Down
9 changes: 9 additions & 0 deletions stdlib/3/tkinter/colorchooser.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from tkinter.commondialog import Dialog
from typing import Any, ClassVar, Optional, Tuple, Union

class Chooser(Dialog):
command: ClassVar[str]

def askcolor(
color: Optional[Union[str, bytes]] = ..., **options: Any
) -> Union[Tuple[None, None], Tuple[Tuple[float, float, float], str]]: ...
4 changes: 2 additions & 2 deletions stdlib/3/tkinter/commondialog.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Any, Mapping, Optional
from typing import Any, ClassVar, Mapping, Optional

class Dialog:
command: Optional[Any] = ...
command: ClassVar[Optional[str]] = ...
master: Optional[Any] = ...
options: Mapping[str, Any] = ...
def __init__(self, master: Optional[Any] = ..., **options) -> None: ...
Expand Down
13 changes: 13 additions & 0 deletions stdlib/3/tkinter/dnd.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from _typeshed.tkinter import DndSource
from tkinter import Event, Misc, Tk
from typing import ClassVar, Optional

class DndHandler:
root: ClassVar[Optional[Tk]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be a ClassVar. It's set in __init__.

def __init__(self, source: DndSource, event: Event[Misc]) -> None: ...
def cancel(self, event: Optional[Event[Misc]] = ...) -> None: ...
def finish(self, event: Optional[Event[Misc]], commit: int = ...) -> None: ...
def on_motion(self, event: Event[Misc]) -> None: ...
def on_release(self, event: Event[Misc]) -> None: ...

def dnd_start(source, event) -> Optional[DndHandler]: ...
8 changes: 4 additions & 4 deletions stdlib/3/tkinter/filedialog.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tkinter import Button, Entry, Frame, Listbox, Scrollbar, Toplevel, commondialog
from typing import Any, Dict, Optional, Tuple
from typing import Any, ClassVar, Dict, Optional, Tuple

dialogstates: Dict[Any, Tuple[Any, Any]]

Expand Down Expand Up @@ -49,13 +49,13 @@ class SaveFileDialog(FileDialog):
class _Dialog(commondialog.Dialog): ...

class Open(_Dialog):
command: str = ...
command: ClassVar[str] = ...

class SaveAs(_Dialog):
command: str = ...
command: ClassVar[str] = ...

class Directory(commondialog.Dialog):
command: str = ...
command: ClassVar[str] = ...

def askopenfilename(**options): ...
def asksaveasfilename(**options): ...
Expand Down
4 changes: 2 additions & 2 deletions stdlib/3/tkinter/messagebox.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from tkinter.commondialog import Dialog
from typing import Any, Optional
from typing import Any, ClassVar, Optional

ERROR: str
INFO: str
Expand All @@ -19,7 +19,7 @@ YES: str
NO: str

class Message(Dialog):
command: str = ...
command: ClassVar[str] = ...

def showinfo(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> str: ...
def showwarning(title: Optional[str] = ..., message: Optional[str] = ..., **options: Any) -> str: ...
Expand Down
8 changes: 8 additions & 0 deletions stdlib/3/tkinter/scrolledtext.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from tkinter import Frame, Grid, Misc, Pack, Place, Scrollbar, Text
from typing import Any, Optional

# The methods from Pack, Place, and Grid are dynamically added over the parent's impls
class ScrolledText(Text):
frame: Frame
vbar: Scrollbar
def __init__(self, master: Optional[Misc] = ..., **kwargs: Any) -> None: ...
27 changes: 27 additions & 0 deletions stdlib/3/tkinter/simpledialog.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from tkinter import Event, Misc, Toplevel
from typing import Any, List, Optional

class Dialog(Toplevel):
def __init__(self, parent: Optional[Misc], title: Optional[str] = ...) -> None: ...
def body(self, master) -> None: ...
def buttonbox(self): ...

class SimpleDialog:
def __init__(
self,
master: Optional[Misc],
text: str = ...,
buttons: List[str] = ...,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be typing.Sequence instead of List, or maybe one of the SupportsFoo classes in _typeshed. It needs to have __getitem__ and __len__, so it could also be e.g. a tuple or a collections.deque. (Note that tkinter._TkinterSequence is the right type for many things in tkinter, but not for this one.)

default: Optional[int] = ...,
cancel: Optional[int] = ...,
title: Optional[str] = ...,
class_: Optional[str] = ...,
) -> None: ...
def go(self) -> Optional[int]: ...
def return_event(self, event: Event[Misc]) -> None: ...
def wm_delete_window(self) -> None: ...
def done(self, num: int) -> None: ...

def askfloat(title: Optional[str], prompt: str, **kwargs: Any) -> float: ...
def askinteger(title: Optional[str], prompt: str, **kwargs: Any) -> int: ...
def askstring(title: Optional[str], prompt: str, **kwargs: Any) -> str: ...
Loading