diff --git a/stdlib/2and3/_typeshed/tkinter.pyi b/stdlib/2and3/_typeshed/tkinter.pyi new file mode 100644 index 000000000000..565635adbb74 --- /dev/null +++ b/stdlib/2and3/_typeshed/tkinter.pyi @@ -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: ... diff --git a/stdlib/3/_tkinter.pyi b/stdlib/3/_tkinter.pyi index bc42dbf86937..c5bf5820a898 100644 --- a/stdlib/3/_tkinter.pyi +++ b/stdlib/3/_tkinter.pyi @@ -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 @@ -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 diff --git a/stdlib/3/tkinter/colorchooser.pyi b/stdlib/3/tkinter/colorchooser.pyi new file mode 100644 index 000000000000..c99c16f0e3bf --- /dev/null +++ b/stdlib/3/tkinter/colorchooser.pyi @@ -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]]: ... diff --git a/stdlib/3/tkinter/commondialog.pyi b/stdlib/3/tkinter/commondialog.pyi index d6a8a0d1f5a6..8efefe468b04 100644 --- a/stdlib/3/tkinter/commondialog.pyi +++ b/stdlib/3/tkinter/commondialog.pyi @@ -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: ... diff --git a/stdlib/3/tkinter/dnd.pyi b/stdlib/3/tkinter/dnd.pyi new file mode 100644 index 000000000000..7371f91b524e --- /dev/null +++ b/stdlib/3/tkinter/dnd.pyi @@ -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]] + 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]: ... diff --git a/stdlib/3/tkinter/filedialog.pyi b/stdlib/3/tkinter/filedialog.pyi index 8c281c6bdbad..86238f0be798 100644 --- a/stdlib/3/tkinter/filedialog.pyi +++ b/stdlib/3/tkinter/filedialog.pyi @@ -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]] @@ -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): ... diff --git a/stdlib/3/tkinter/messagebox.pyi b/stdlib/3/tkinter/messagebox.pyi index b44e66081fab..b291a45e87c9 100644 --- a/stdlib/3/tkinter/messagebox.pyi +++ b/stdlib/3/tkinter/messagebox.pyi @@ -1,5 +1,5 @@ from tkinter.commondialog import Dialog -from typing import Any, Optional +from typing import Any, ClassVar, Optional ERROR: str INFO: str @@ -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: ... diff --git a/stdlib/3/tkinter/scrolledtext.pyi b/stdlib/3/tkinter/scrolledtext.pyi new file mode 100644 index 000000000000..12c614072ba2 --- /dev/null +++ b/stdlib/3/tkinter/scrolledtext.pyi @@ -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: ... diff --git a/stdlib/3/tkinter/simpledialog.pyi b/stdlib/3/tkinter/simpledialog.pyi new file mode 100644 index 000000000000..b29bb7bfc153 --- /dev/null +++ b/stdlib/3/tkinter/simpledialog.pyi @@ -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] = ..., + 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: ... diff --git a/stdlib/3/tkinter/tix.pyi b/stdlib/3/tkinter/tix.pyi new file mode 100644 index 000000000000..78493900f119 --- /dev/null +++ b/stdlib/3/tkinter/tix.pyi @@ -0,0 +1,305 @@ +import tkinter +from typing import Any, Dict, List, Optional, Tuple +from typing_extensions import Literal + +WINDOW: Literal["window"] +TEXT: Literal["text"] +STATUS: Literal["status"] +IMMEDIATE: Literal["immediate"] +IMAGE: Literal["image"] +IMAGETEXT: Literal["imagetext"] +BALLOON: Literal["balloon"] +AUTO: Literal["auto"] +ACROSSTOP: Literal["acrosstop"] + +ASCII: Literal["ascii"] +CELL: Literal["cell"] +COLUMN: Literal["column"] +DECREASING: Literal["decreasing"] +INCREASING: Literal["increasing"] +INTEGER: Literal["integer"] +MAIN: Literal["main"] +MAX: Literal["max"] +REAL: Literal["real"] +ROW: Literal["row"] +S_REGION: Literal["s-region"] +X_REGION: Literal["x-region"] +Y_REGION: Literal["y-region"] + +# These should be kept in sync with _tkinter constants, except TCL_ALL_EVENTS which doesn't match ALL_EVENTS +TCL_DONT_WAIT: Literal[2] +TCL_WINDOW_EVENTS: Literal[4] +TCL_FILE_EVENTS: Literal[8] +TCL_TIMER_EVENTS: Literal[16] +TCL_IDLE_EVENTS: Literal[32] +TCL_ALL_EVENTS: Literal[0] + +class tixCommand: + def tix_addbitmapdir(self, directory: str) -> None: ... + def tix_cget(self, option: str) -> Any: ... + def tix_configure(self, cnf: Optional[Dict[str, Any]] = ..., **kw: Any) -> Any: ... + def tix_filedialog(self, dlgclass: Optional[str] = ...) -> str: ... + def tix_getbitmap(self, name: str) -> str: ... + def tix_getimage(self, name: str) -> str: ... + def tix_option_get(self, name: str) -> Any: ... + def tix_resetoptions(self, newScheme: str, newFontSet: str, newScmPrio: Optional[str] = ...) -> None: ... + +class Tk(tkinter.Tk, tixCommand): + def __init__(self, screenName: Optional[str] = ..., baseName: Optional[str] = ..., className: str = ...): ... + +class TixWidget(tkinter.Widget): + def __init__( + self, + master: Optional[tkinter.Misc] = ..., + widgetName: Optional[str] = ..., + static_options: Optional[List[str]] = ..., + cnf: Dict[str, Any] = ..., + kw: Dict[str, Any] = ..., + ) -> None: ... + def __getattr__(self, name: str) -> Any: ... + def set_silent(self, value: str) -> None: ... + def subwidget(self, name: str) -> tkinter.Widget: ... + def subwidgets_all(self) -> List[tkinter.Widget]: ... + def config_all(self, option: Any, value: Any) -> None: ... + def image_create( + self, imgtype: str, cnf: Dict[str, Any] = ..., master: Optional[tkinter.Widget] = ..., **kw: Any + ) -> None: ... + def image_delete(self, imgname: str) -> None: ... + +class TixSubWidget(TixWidget): + def __init__( + self, master: tkinter.Widget, name: str, destroy_physically: int = ..., check_intermediate: int = ... + ) -> None: ... + +class DisplayStyle: + def __init__( + self, itemtype: str, cnf: Dict[str, Any] = ..., *, master: Optional[tkinter.Widget] = ..., **kw: Any + ) -> None: ... + def __getitem__(self, key: str) -> Any: ... + def __setitem__(self, key: str, value: Any) -> None: ... + def delete(self) -> None: ... + def config(self, cnf: Dict[str, Any] = ..., **kw: Any) -> Any: ... + +class Balloon(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def bind_widget(self, widget: tkinter.Widget, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def unbind_widget(self, widget: tkinter.Widget) -> None: ... + +class ButtonBox(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def add(self, name: str, cnf: Dict[str, Any] = ..., **kw: Any) -> tkinter.Widget: ... + def invoke(self, name: str) -> None: ... + +class ComboBox(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def add_history(self, str: str) -> None: ... + def append_history(self, str: str) -> None: ... + def insert(self, index: int, str: str) -> None: ... + def pick(self, index: int) -> None: ... + +class Control(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def decrement(self) -> None: ... + def increment(self) -> None: ... + def invoke(self) -> None: ... + +class LabelEntry(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + +class LabelFrame(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + +class Meter(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + +class OptionMenu(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def add_command(self, name: str, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def add_separator(self, name: str, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def delete(self, name: str) -> None: ... + def disable(self, name: str) -> None: ... + def enable(self, name: str) -> None: ... + +class PopupMenu(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def bind_widget(self, widget: tkinter.Widget) -> None: ... + def unbind_widget(self, widget: tkinter.Widget) -> None: ... + def post_widget(self, widget: tkinter.Widget, x: int, y: int) -> None: ... + +class Select(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def add(self, name: str, cnf: Dict[str, Any] = ..., **kw: Any) -> tkinter.Widget: ... + def invoke(self, name: str) -> None: ... + +class StdButtonBox(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def invoke(self, name: str) -> None: ... + +class DirList(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def chdir(self, dir: str) -> None: ... + +class DirTree(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def chdir(self, dir: str) -> None: ... + +class DirSelectDialog(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def popup(self) -> None: ... + def popdown(self) -> None: ... + +class DirSelectBox(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + +class ExFileSelectBox(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def filter(self) -> None: ... + def invoke(self) -> None: ... + +class FileSelectBox(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def apply_filter(self) -> None: ... + def invoke(self) -> None: ... + +class FileEntry(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def invoke(self) -> None: ... + def file_dialog(self) -> None: ... + +class HList(TixWidget, tkinter.XView, tkinter.YView): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def add(self, entry: str, cnf: Dict[str, Any] = ..., **kw: Any) -> tkinter.Widget: ... + def add_child(self, parent: Optional[str] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> tkinter.Widget: ... + def anchor_set(self, entry: str) -> None: ... + def anchor_clear(self) -> None: ... + # FIXME: Overload, certain combos return, others don't + def column_width(self, col: int = ..., width: Optional[int] = ..., chars: Optional[int] = ...) -> Optional[int]: ... + def delete_all(self) -> None: ... + def delete_entry(self, entry: str) -> None: ... + def delete_offsprings(self, entry: str) -> None: ... + def delete_siblings(self, entry: str) -> None: ... + def dragsite_set(self, index: int) -> None: ... + def dragsite_clear(self) -> None: ... + def dropsite_set(self, index: int) -> None: ... + def dropsite_clear(self) -> None: ... + def header_create(self, col: int, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def header_configure(self, col: int, cnf: Dict[str, Any] = ..., **kw: Any) -> Optional[Any]: ... + def header_cget(self, col: int, opt: Any) -> Any: ... + def header_exists(self, col: int) -> bool: ... + def header_exist(self, col: int) -> bool: ... + def header_delete(self, col: int) -> None: ... + def header_size(self, col: int) -> int: ... + def hide_entry(self, entry: str) -> None: ... + def indicator_create(self, entry: str, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def indicator_configure(self, entry: str, cnf: Dict[str, Any] = ..., **kw: Any) -> Optional[Any]: ... + def indicator_cget(self, entry: str, opt: Any) -> Any: ... + def indicator_exists(self, entry: str) -> bool: ... + def indicator_delete(self, entry: str) -> None: ... + def indicator_size(self, entry: str) -> int: ... + def info_anchor(self) -> str: ... + def info_bbox(self, entry: str) -> Tuple[int, int, int, int]: ... + def info_children(self, entry: Optional[str] = ...) -> Tuple[str, ...]: ... + def info_data(self, entry: str) -> Any: ... + def info_dragsite(self) -> str: ... + def info_dropsite(self) -> str: ... + def info_exists(self, entry: str) -> bool: ... + def info_hidden(self, entry: str) -> bool: ... + def info_next(self, entry: str) -> str: ... + def info_parent(self, entry: str) -> str: ... + def info_prev(self, entry: str) -> str: ... + def info_selection(self) -> Tuple[str, ...]: ... + def item_cget(self, entry: str, col: int, opt: Any) -> Any: ... + def item_configure(self, entry: str, col: int, cnf: Dict[str, Any] = ..., **kw: Any) -> Optional[Any]: ... + def item_create(self, entry: str, col: int, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def item_exists(self, entry: str, col: int) -> bool: ... + def item_delete(self, entry: str, col: int) -> None: ... + def entrycget(self, entry: str, opt: Any) -> Any: ... + def entryconfigure(self, entry: str, cnf: Dict[str, Any] = ..., **kw: Any) -> Optional[Any]: ... + def nearest(self, y: int) -> str: ... + def see(self, entry: str) -> None: ... + def selection_clear(self, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def selection_includes(self, entry: str) -> bool: ... + def selection_set(self, first: str, last: Optional[str] = ...) -> None: ... + def show_entry(self, entry: str) -> None: ... + +class CheckList(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def autosetmode(self) -> None: ... + def close(self, entrypath: str) -> None: ... + def getmode(self, entrypath: str) -> str: ... + def open(self, entrypath: str) -> None: ... + def getselection(self, mode: str = ...) -> Tuple[str, ...]: ... + def getstatus(self, entrypath: str) -> str: ... + def setstatus(self, entrypath: str, mode: str = ...) -> None: ... + +class Tree(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def autosetmode(self) -> None: ... + def close(self, entrypath: str) -> None: ... + def getmode(self, entrypath: str) -> str: ... + def open(self, entrypath: str) -> None: ... + def setmode(self, entrypath: str, mode: str = ...) -> None: ... + +class TList(TixWidget, tkinter.XView, tkinter.YView): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def active_set(self, index: int) -> None: ... + def active_clear(self) -> None: ... + def anchor_set(self, index: int) -> None: ... + def anchor_clear(self) -> None: ... + def delete(self, from_: int, to: Optional[int] = ...) -> None: ... + def dragsite_set(self, index: int) -> None: ... + def dragsite_clear(self) -> None: ... + def dropsite_set(self, index: int) -> None: ... + def dropsite_clear(self) -> None: ... + def insert(self, index: int, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def info_active(self) -> int: ... + def info_anchor(self) -> int: ... + def info_down(self, index: int) -> int: ... + def info_left(self, index: int) -> int: ... + def info_right(self, index: int) -> int: ... + def info_selection(self) -> Tuple[int, ...]: ... + def info_size(self) -> int: ... + def info_up(self, index: int) -> int: ... + def nearest(self, x: int, y: int) -> int: ... + def see(self, index: int) -> None: ... + def selection_clear(self, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def selection_includes(self, index: int) -> bool: ... + def selection_set(self, first: int, last: Optional[int] = ...) -> None: ... + +class PanedWindow(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def add(self, name: str, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def delete(self, name: str) -> None: ... + def forget(self, name: str) -> None: ... # type: ignore + def panecget(self, entry: str, opt: Any) -> Any: ... + def paneconfigure(self, entry: str, cnf: Dict[str, Any] = ..., **kw: Any) -> Optional[Any]: ... + def panes(self) -> List[tkinter.Widget]: ... + +class ListNoteBook(TixWidget): + def __init__(self, master: Optional[tkinter.Widget], cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def add(self, name: str, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def page(self, name: str) -> tkinter.Widget: ... + def pages(self) -> List[tkinter.Widget]: ... + def raise_page(self, name: str) -> None: ... + +class NoteBook(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def add(self, name: str, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def delete(self, name: str) -> None: ... + def page(self, name: str) -> tkinter.Widget: ... + def pages(self) -> List[tkinter.Widget]: ... + def raise_page(self, name: str) -> None: ... + def raised(self) -> bool: ... + +class InputOnly(TixWidget): + def __init__(self, master: Optional[tkinter.Widget] = ..., cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + +class Form: + def __setitem__(self, key: str, value: Any) -> None: ... + def config(self, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def form(self, cnf: Dict[str, Any] = ..., **kw: Any) -> None: ... + def check(self) -> bool: ... + def forget(self) -> None: ... + def grid(self, xsize: int = ..., ysize: int = ...) -> Optional[Tuple[int, int]]: ... + def info(self, option: Optional[str] = ...) -> Any: ... + def slaves(self) -> List[tkinter.Widget]: ...