-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
__init__.pyi
3715 lines (3644 loc) · 136 KB
/
__init__.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import _tkinter
import sys
from _typeshed import Incomplete, StrEnum, StrOrBytesPath
from collections.abc import Callable, Iterable, Mapping, Sequence
from tkinter.constants import *
from tkinter.font import _FontDescription
from types import TracebackType
from typing import Any, Generic, Literal, NamedTuple, TypedDict, TypeVar, overload, type_check_only
from typing_extensions import TypeAlias, TypeVarTuple, Unpack, deprecated
if sys.version_info >= (3, 9):
__all__ = [
"TclError",
"NO",
"FALSE",
"OFF",
"YES",
"TRUE",
"ON",
"N",
"S",
"W",
"E",
"NW",
"SW",
"NE",
"SE",
"NS",
"EW",
"NSEW",
"CENTER",
"NONE",
"X",
"Y",
"BOTH",
"LEFT",
"TOP",
"RIGHT",
"BOTTOM",
"RAISED",
"SUNKEN",
"FLAT",
"RIDGE",
"GROOVE",
"SOLID",
"HORIZONTAL",
"VERTICAL",
"NUMERIC",
"CHAR",
"WORD",
"BASELINE",
"INSIDE",
"OUTSIDE",
"SEL",
"SEL_FIRST",
"SEL_LAST",
"END",
"INSERT",
"CURRENT",
"ANCHOR",
"ALL",
"NORMAL",
"DISABLED",
"ACTIVE",
"HIDDEN",
"CASCADE",
"CHECKBUTTON",
"COMMAND",
"RADIOBUTTON",
"SEPARATOR",
"SINGLE",
"BROWSE",
"MULTIPLE",
"EXTENDED",
"DOTBOX",
"UNDERLINE",
"PIESLICE",
"CHORD",
"ARC",
"FIRST",
"LAST",
"BUTT",
"PROJECTING",
"ROUND",
"BEVEL",
"MITER",
"MOVETO",
"SCROLL",
"UNITS",
"PAGES",
"TkVersion",
"TclVersion",
"READABLE",
"WRITABLE",
"EXCEPTION",
"EventType",
"Event",
"NoDefaultRoot",
"Variable",
"StringVar",
"IntVar",
"DoubleVar",
"BooleanVar",
"mainloop",
"getint",
"getdouble",
"getboolean",
"Misc",
"CallWrapper",
"XView",
"YView",
"Wm",
"Tk",
"Tcl",
"Pack",
"Place",
"Grid",
"BaseWidget",
"Widget",
"Toplevel",
"Button",
"Canvas",
"Checkbutton",
"Entry",
"Frame",
"Label",
"Listbox",
"Menu",
"Menubutton",
"Message",
"Radiobutton",
"Scale",
"Scrollbar",
"Text",
"OptionMenu",
"Image",
"PhotoImage",
"BitmapImage",
"image_names",
"image_types",
"Spinbox",
"LabelFrame",
"PanedWindow",
]
# 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: int
TkVersion: float
TclVersion: float
READABLE = _tkinter.READABLE
WRITABLE = _tkinter.WRITABLE
EXCEPTION = _tkinter.EXCEPTION
# 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
#
# Don't trust tkinter's docstrings, because they have been created by copy/pasting from
# Tk's manual pages more than 10 years ago. Use the latest manual pages instead:
#
# $ sudo apt install tk-doc tcl-doc
# $ man 3tk label # tkinter.Label
# $ man 3tk ttk_label # tkinter.ttk.Label
# $ man 3tcl after # tkinter.Misc.after
#
# You can also read the manual pages online: https://www.tcl.tk/doc/
# Some widgets have an option named -compound that accepts different values
# than the _Compound defined here. Many other options have similar things.
_Anchor: TypeAlias = Literal["nw", "n", "ne", "w", "center", "e", "sw", "s", "se"] # manual page: Tk_GetAnchor
_ButtonCommand: TypeAlias = str | Callable[[], Any] # accepts string of tcl code, return value is returned from Button.invoke()
_Compound: TypeAlias = Literal["top", "left", "center", "right", "bottom", "none"] # -compound in manual page named 'options'
# manual page: Tk_GetCursor
_Cursor: TypeAlias = str | tuple[str] | tuple[str, str] | tuple[str, str, str] | tuple[str, str, str, str]
# example when it's sequence: entry['invalidcommand'] = [entry.register(print), '%P']
_EntryValidateCommand: TypeAlias = str | list[str] | tuple[str, ...] | Callable[[], bool]
_ImageSpec: TypeAlias = _Image | str # str can be from e.g. tkinter.image_names()
_Relief: TypeAlias = Literal["raised", "sunken", "flat", "ridge", "solid", "groove"] # manual page: Tk_GetRelief
_ScreenUnits: TypeAlias = str | float # Often the right type instead of int. Manual page: Tk_GetPixels
# -xscrollcommand and -yscrollcommand in 'options' manual page
_XYScrollCommand: TypeAlias = str | Callable[[float, float], object]
_TakeFocusValue: TypeAlias = bool | Literal[0, 1, ""] | Callable[[str], bool | None] # -takefocus in manual page named 'options'
if sys.version_info >= (3, 11):
class _VersionInfoType(NamedTuple):
major: int
minor: int
micro: int
releaselevel: str
serial: int
class EventType(StrEnum):
Activate = "36"
ButtonPress = "4"
Button = ButtonPress
ButtonRelease = "5"
Circulate = "26"
CirculateRequest = "27"
ClientMessage = "33"
Colormap = "32"
Configure = "22"
ConfigureRequest = "23"
Create = "16"
Deactivate = "37"
Destroy = "17"
Enter = "7"
Expose = "12"
FocusIn = "9"
FocusOut = "10"
GraphicsExpose = "13"
Gravity = "24"
KeyPress = "2"
Key = "2"
KeyRelease = "3"
Keymap = "11"
Leave = "8"
Map = "19"
MapRequest = "20"
Mapping = "34"
Motion = "6"
MouseWheel = "38"
NoExpose = "14"
Property = "28"
Reparent = "21"
ResizeRequest = "25"
Selection = "31"
SelectionClear = "29"
SelectionRequest = "30"
Unmap = "18"
VirtualEvent = "35"
Visibility = "15"
_W = TypeVar("_W", bound=Misc)
# Events considered covariant because you should never assign to event.widget.
_W_co = TypeVar("_W_co", covariant=True, bound=Misc)
class Event(Generic[_W_co]):
serial: int
num: int
focus: bool
height: int
width: int
keycode: int
state: int | str
time: int
x: int
y: int
x_root: int
y_root: int
char: str
send_event: bool
keysym: str
keysym_num: int
type: EventType
widget: _W_co
delta: int
def NoDefaultRoot() -> None: ...
class Variable:
def __init__(self, master: Misc | None = None, value: Incomplete | None = None, name: str | None = None) -> None: ...
def set(self, value) -> None: ...
initialize = set
def get(self): ...
def trace_add(self, mode: Literal["array", "read", "write", "unset"], callback: Callable[[str, str, str], object]) -> str: ...
def trace_remove(self, mode: Literal["array", "read", "write", "unset"], cbname: str) -> None: ...
def trace_info(self) -> list[tuple[tuple[Literal["array", "read", "write", "unset"], ...], str]]: ...
@deprecated("use trace_add() instead of trace()")
def trace(self, mode, callback): ...
@deprecated("use trace_add() instead of trace_variable()")
def trace_variable(self, mode, callback): ...
@deprecated("use trace_remove() instead of trace_vdelete()")
def trace_vdelete(self, mode, cbname) -> None: ...
@deprecated("use trace_info() instead of trace_vinfo()")
def trace_vinfo(self): ...
def __eq__(self, other: object) -> bool: ...
def __del__(self) -> None: ...
class StringVar(Variable):
def __init__(self, master: Misc | None = None, value: str | None = None, name: str | None = None) -> None: ...
def set(self, value: str) -> None: ...
initialize = set
def get(self) -> str: ...
class IntVar(Variable):
def __init__(self, master: Misc | None = None, value: int | None = None, name: str | None = None) -> None: ...
def set(self, value: int) -> None: ...
initialize = set
def get(self) -> int: ...
class DoubleVar(Variable):
def __init__(self, master: Misc | None = None, value: float | None = None, name: str | None = None) -> None: ...
def set(self, value: float) -> None: ...
initialize = set
def get(self) -> float: ...
class BooleanVar(Variable):
def __init__(self, master: Misc | None = None, value: bool | None = None, name: str | None = None) -> None: ...
def set(self, value: bool) -> None: ...
initialize = set
def get(self) -> bool: ...
def mainloop(n: int = 0) -> None: ...
getint: Incomplete
getdouble: Incomplete
def getboolean(s): ...
_Ts = TypeVarTuple("_Ts")
class _GridIndexInfo(TypedDict, total=False):
minsize: _ScreenUnits
pad: _ScreenUnits
uniform: str | None
weight: int
class Misc:
master: Misc | None
tk: _tkinter.TkappType
children: dict[str, Widget]
def destroy(self) -> None: ...
def deletecommand(self, name: str) -> None: ...
def tk_strictMotif(self, boolean: Incomplete | None = None): ...
def tk_bisque(self) -> None: ...
def tk_setPalette(self, *args, **kw) -> None: ...
def wait_variable(self, name: str | Variable = "PY_VAR") -> None: ...
waitvar = wait_variable
def wait_window(self, window: Misc | None = None) -> None: ...
def wait_visibility(self, window: Misc | None = None) -> None: ...
def setvar(self, name: str = "PY_VAR", value: str = "1") -> None: ...
def getvar(self, name: str = "PY_VAR"): ...
def getint(self, s): ...
def getdouble(self, s): ...
def getboolean(self, s): ...
def focus_set(self) -> None: ...
focus = focus_set
def focus_force(self) -> None: ...
def focus_get(self) -> Misc | None: ...
def focus_displayof(self) -> Misc | None: ...
def focus_lastfor(self) -> Misc | None: ...
def tk_focusFollowsMouse(self) -> None: ...
def tk_focusNext(self) -> Misc | None: ...
def tk_focusPrev(self) -> Misc | None: ...
# .after() can be called without the "func" argument, but it is basically never what you want.
# It behaves like time.sleep() and freezes the GUI app.
def after(self, ms: int | Literal["idle"], func: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> str: ...
# after_idle is essentially partialmethod(after, "idle")
def after_idle(self, func: Callable[[Unpack[_Ts]], object], *args: Unpack[_Ts]) -> str: ...
def after_cancel(self, id: str) -> None: ...
def bell(self, displayof: Literal[0] | Misc | None = 0) -> None: ...
def clipboard_get(self, *, displayof: Misc = ..., type: str = ...) -> str: ...
def clipboard_clear(self, *, displayof: Misc = ...) -> None: ...
def clipboard_append(self, string: str, *, displayof: Misc = ..., format: str = ..., type: str = ...) -> None: ...
def grab_current(self): ...
def grab_release(self) -> None: ...
def grab_set(self) -> None: ...
def grab_set_global(self) -> None: ...
def grab_status(self) -> Literal["local", "global"] | None: ...
def option_add(
self, pattern, value, priority: int | Literal["widgetDefault", "startupFile", "userDefault", "interactive"] | None = None
) -> None: ...
def option_clear(self) -> None: ...
def option_get(self, name, className): ...
def option_readfile(self, fileName, priority: Incomplete | None = None) -> None: ...
def selection_clear(self, **kw) -> None: ...
def selection_get(self, **kw): ...
def selection_handle(self, command, **kw) -> None: ...
def selection_own(self, **kw) -> None: ...
def selection_own_get(self, **kw): ...
def send(self, interp, cmd, *args): ...
def lower(self, belowThis: Incomplete | None = None) -> None: ...
def tkraise(self, aboveThis: Incomplete | None = None) -> None: ...
lift = tkraise
if sys.version_info >= (3, 11):
def info_patchlevel(self) -> _VersionInfoType: ...
def winfo_atom(self, name: str, displayof: Literal[0] | Misc | None = 0) -> int: ...
def winfo_atomname(self, id: int, displayof: Literal[0] | Misc | None = 0) -> str: ...
def winfo_cells(self) -> int: ...
def winfo_children(self) -> list[Widget]: ... # Widget because it can't be Toplevel or Tk
def winfo_class(self) -> str: ...
def winfo_colormapfull(self) -> bool: ...
def winfo_containing(self, rootX: int, rootY: int, displayof: Literal[0] | Misc | None = 0) -> Misc | None: ...
def winfo_depth(self) -> int: ...
def winfo_exists(self) -> bool: ...
def winfo_fpixels(self, number: _ScreenUnits) -> float: ...
def winfo_geometry(self) -> str: ...
def winfo_height(self) -> int: ...
def winfo_id(self) -> int: ...
def winfo_interps(self, displayof: Literal[0] | Misc | None = 0) -> tuple[str, ...]: ...
def winfo_ismapped(self) -> bool: ...
def winfo_manager(self) -> str: ...
def winfo_name(self) -> str: ...
def winfo_parent(self) -> str: ... # return value needs nametowidget()
def winfo_pathname(self, id: int, displayof: Literal[0] | Misc | None = 0): ...
def winfo_pixels(self, number: _ScreenUnits) -> int: ...
def winfo_pointerx(self) -> int: ...
def winfo_pointerxy(self) -> tuple[int, int]: ...
def winfo_pointery(self) -> int: ...
def winfo_reqheight(self) -> int: ...
def winfo_reqwidth(self) -> int: ...
def winfo_rgb(self, color: str) -> tuple[int, int, int]: ...
def winfo_rootx(self) -> int: ...
def winfo_rooty(self) -> int: ...
def winfo_screen(self) -> str: ...
def winfo_screencells(self) -> int: ...
def winfo_screendepth(self) -> int: ...
def winfo_screenheight(self) -> int: ...
def winfo_screenmmheight(self) -> int: ...
def winfo_screenmmwidth(self) -> int: ...
def winfo_screenvisual(self) -> str: ...
def winfo_screenwidth(self) -> int: ...
def winfo_server(self) -> str: ...
def winfo_toplevel(self) -> Tk | Toplevel: ...
def winfo_viewable(self) -> bool: ...
def winfo_visual(self) -> str: ...
def winfo_visualid(self) -> str: ...
def winfo_visualsavailable(self, includeids: bool = False) -> list[tuple[str, int]]: ...
def winfo_vrootheight(self) -> int: ...
def winfo_vrootwidth(self) -> int: ...
def winfo_vrootx(self) -> int: ...
def winfo_vrooty(self) -> int: ...
def winfo_width(self) -> int: ...
def winfo_x(self) -> int: ...
def winfo_y(self) -> int: ...
def update(self) -> None: ...
def update_idletasks(self) -> None: ...
@overload
def bindtags(self, tagList: None = None) -> tuple[str, ...]: ...
@overload
def bindtags(self, tagList: list[str] | tuple[str, ...]) -> None: ...
# bind with isinstance(func, str) doesn't return anything, but all other
# binds do. The default value of func is not str.
@overload
def bind(
self,
sequence: str | None = None,
func: Callable[[Event[Misc]], object] | None = None,
add: Literal["", "+"] | bool | None = None,
) -> str: ...
@overload
def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = None) -> None: ...
@overload
def bind(self, *, func: str, add: Literal["", "+"] | bool | None = None) -> None: ...
# There's no way to know what type of widget bind_all and bind_class
# callbacks will get, so those are Misc.
@overload
def bind_all(
self,
sequence: str | None = None,
func: Callable[[Event[Misc]], object] | None = None,
add: Literal["", "+"] | bool | None = None,
) -> str: ...
@overload
def bind_all(self, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = None) -> None: ...
@overload
def bind_all(self, *, func: str, add: Literal["", "+"] | bool | None = None) -> None: ...
@overload
def bind_class(
self,
className: str,
sequence: str | None = None,
func: Callable[[Event[Misc]], object] | None = None,
add: Literal["", "+"] | bool | None = None,
) -> str: ...
@overload
def bind_class(self, className: str, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = None) -> None: ...
@overload
def bind_class(self, className: str, *, func: str, add: Literal["", "+"] | bool | None = None) -> None: ...
def unbind(self, sequence: str, funcid: str | None = None) -> None: ...
def unbind_all(self, sequence: str) -> None: ...
def unbind_class(self, className: str, sequence: str) -> None: ...
def mainloop(self, n: int = 0) -> None: ...
def quit(self) -> None: ...
@property
def _windowingsystem(self) -> Literal["win32", "aqua", "x11"]: ...
def nametowidget(self, name: str | Misc | _tkinter.Tcl_Obj) -> Any: ...
def register(
self, func: Callable[..., object], subst: Callable[..., Sequence[Any]] | None = None, needcleanup: int = 1
) -> str: ...
def keys(self) -> list[str]: ...
@overload
def pack_propagate(self, flag: bool) -> bool | None: ...
@overload
def pack_propagate(self) -> None: ...
propagate = pack_propagate
def grid_anchor(self, anchor: _Anchor | None = None) -> None: ...
anchor = grid_anchor
@overload
def grid_bbox(
self, column: None = None, row: None = None, col2: None = None, row2: None = None
) -> tuple[int, int, int, int] | None: ...
@overload
def grid_bbox(self, column: int, row: int, col2: None = None, row2: None = None) -> tuple[int, int, int, int] | None: ...
@overload
def grid_bbox(self, column: int, row: int, col2: int, row2: int) -> tuple[int, int, int, int] | None: ...
bbox = grid_bbox
def grid_columnconfigure(
self,
index: int | str | list[int] | tuple[int, ...],
cnf: _GridIndexInfo = {},
*,
minsize: _ScreenUnits = ...,
pad: _ScreenUnits = ...,
uniform: str = ...,
weight: int = ...,
) -> _GridIndexInfo | Any: ... # can be None but annoying to check
def grid_rowconfigure(
self,
index: int | str | list[int] | tuple[int, ...],
cnf: _GridIndexInfo = {},
*,
minsize: _ScreenUnits = ...,
pad: _ScreenUnits = ...,
uniform: str = ...,
weight: int = ...,
) -> _GridIndexInfo | Any: ... # can be None but annoying to check
columnconfigure = grid_columnconfigure
rowconfigure = grid_rowconfigure
def grid_location(self, x: _ScreenUnits, y: _ScreenUnits) -> tuple[int, int]: ...
@overload
def grid_propagate(self, flag: bool) -> None: ...
@overload
def grid_propagate(self) -> bool: ...
def grid_size(self) -> tuple[int, int]: ...
size = grid_size
# Widget because Toplevel or Tk is never a slave
def pack_slaves(self) -> list[Widget]: ...
def grid_slaves(self, row: int | None = None, column: int | None = None) -> list[Widget]: ...
def place_slaves(self) -> list[Widget]: ...
slaves = pack_slaves
def event_add(self, virtual: str, *sequences: str) -> None: ...
def event_delete(self, virtual: str, *sequences: str) -> None: ...
def event_generate(
self,
sequence: str,
*,
above: Misc | int = ...,
borderwidth: _ScreenUnits = ...,
button: int = ...,
count: int = ...,
data: Any = ..., # anything with usable str() value
delta: int = ...,
detail: str = ...,
focus: bool = ...,
height: _ScreenUnits = ...,
keycode: int = ...,
keysym: str = ...,
mode: str = ...,
override: bool = ...,
place: Literal["PlaceOnTop", "PlaceOnBottom"] = ...,
root: Misc | int = ...,
rootx: _ScreenUnits = ...,
rooty: _ScreenUnits = ...,
sendevent: bool = ...,
serial: int = ...,
state: int | str = ...,
subwindow: Misc | int = ...,
time: int = ...,
warp: bool = ...,
width: _ScreenUnits = ...,
when: Literal["now", "tail", "head", "mark"] = ...,
x: _ScreenUnits = ...,
y: _ScreenUnits = ...,
) -> None: ...
def event_info(self, virtual: str | None = None) -> tuple[str, ...]: ...
def image_names(self) -> tuple[str, ...]: ...
def image_types(self) -> tuple[str, ...]: ...
# See #4363 and #4891
def __setitem__(self, key: str, value: Any) -> None: ...
def __getitem__(self, key: str) -> Any: ...
def cget(self, key: str) -> Any: ...
def configure(self, cnf: Any = None) -> Any: ...
# TODO: config is an alias of configure, but adding that here creates lots of mypy errors
class CallWrapper:
func: Incomplete
subst: Incomplete
widget: Incomplete
def __init__(self, func, subst, widget) -> None: ...
def __call__(self, *args): ...
class XView:
@overload
def xview(self) -> tuple[float, float]: ...
@overload
def xview(self, *args): ...
def xview_moveto(self, fraction: float) -> None: ...
@overload
def xview_scroll(self, number: int, what: Literal["units", "pages"]) -> None: ...
@overload
def xview_scroll(self, number: _ScreenUnits, what: Literal["pixels"]) -> None: ...
class YView:
@overload
def yview(self) -> tuple[float, float]: ...
@overload
def yview(self, *args): ...
def yview_moveto(self, fraction: float) -> None: ...
@overload
def yview_scroll(self, number: int, what: Literal["units", "pages"]) -> None: ...
@overload
def yview_scroll(self, number: _ScreenUnits, what: Literal["pixels"]) -> None: ...
class Wm:
@overload
def wm_aspect(self, minNumer: int, minDenom: int, maxNumer: int, maxDenom: int) -> None: ...
@overload
def wm_aspect(
self, minNumer: None = None, minDenom: None = None, maxNumer: None = None, maxDenom: None = None
) -> tuple[int, int, int, int] | None: ...
aspect = wm_aspect
@overload
def wm_attributes(self) -> tuple[Any, ...]: ...
@overload
def wm_attributes(self, option: str, /): ...
@overload
def wm_attributes(self, option: str, value, /, *__other_option_value_pairs: Any) -> None: ...
attributes = wm_attributes
def wm_client(self, name: str | None = None) -> str: ...
client = wm_client
@overload
def wm_colormapwindows(self) -> list[Misc]: ...
@overload
def wm_colormapwindows(self, wlist: list[Misc] | tuple[Misc, ...], /) -> None: ...
@overload
def wm_colormapwindows(self, first_wlist_item: Misc, /, *other_wlist_items: Misc) -> None: ...
colormapwindows = wm_colormapwindows
def wm_command(self, value: str | None = None) -> str: ...
command = wm_command
# Some of these always return empty string, but return type is set to None to prevent accidentally using it
def wm_deiconify(self) -> None: ...
deiconify = wm_deiconify
def wm_focusmodel(self, model: Literal["active", "passive"] | None = None) -> Literal["active", "passive", ""]: ...
focusmodel = wm_focusmodel
def wm_forget(self, window: Wm) -> None: ...
forget = wm_forget
def wm_frame(self) -> str: ...
frame = wm_frame
@overload
def wm_geometry(self, newGeometry: None = None) -> str: ...
@overload
def wm_geometry(self, newGeometry: str) -> None: ...
geometry = wm_geometry
def wm_grid(
self,
baseWidth: Incomplete | None = None,
baseHeight: Incomplete | None = None,
widthInc: Incomplete | None = None,
heightInc: Incomplete | None = None,
): ...
grid = wm_grid
def wm_group(self, pathName: Incomplete | None = None): ...
group = wm_group
def wm_iconbitmap(self, bitmap: Incomplete | None = None, default: Incomplete | None = None): ...
iconbitmap = wm_iconbitmap
def wm_iconify(self) -> None: ...
iconify = wm_iconify
def wm_iconmask(self, bitmap: Incomplete | None = None): ...
iconmask = wm_iconmask
def wm_iconname(self, newName: Incomplete | None = None) -> str: ...
iconname = wm_iconname
def wm_iconphoto(self, default: bool, image1: _PhotoImageLike | str, /, *args: _PhotoImageLike | str) -> None: ...
iconphoto = wm_iconphoto
def wm_iconposition(self, x: int | None = None, y: int | None = None) -> tuple[int, int] | None: ...
iconposition = wm_iconposition
def wm_iconwindow(self, pathName: Incomplete | None = None): ...
iconwindow = wm_iconwindow
def wm_manage(self, widget) -> None: ...
manage = wm_manage
@overload
def wm_maxsize(self, width: None = None, height: None = None) -> tuple[int, int]: ...
@overload
def wm_maxsize(self, width: int, height: int) -> None: ...
maxsize = wm_maxsize
@overload
def wm_minsize(self, width: None = None, height: None = None) -> tuple[int, int]: ...
@overload
def wm_minsize(self, width: int, height: int) -> None: ...
minsize = wm_minsize
@overload
def wm_overrideredirect(self, boolean: None = None) -> bool | None: ... # returns True or None
@overload
def wm_overrideredirect(self, boolean: bool) -> None: ...
overrideredirect = wm_overrideredirect
def wm_positionfrom(self, who: Literal["program", "user"] | None = None) -> Literal["", "program", "user"]: ...
positionfrom = wm_positionfrom
@overload
def wm_protocol(self, name: str, func: Callable[[], object] | str) -> None: ...
@overload
def wm_protocol(self, name: str, func: None = None) -> str: ...
@overload
def wm_protocol(self, name: None = None, func: None = None) -> tuple[str, ...]: ...
protocol = wm_protocol
@overload
def wm_resizable(self, width: None = None, height: None = None) -> tuple[bool, bool]: ...
@overload
def wm_resizable(self, width: bool, height: bool) -> None: ...
resizable = wm_resizable
def wm_sizefrom(self, who: Literal["program", "user"] | None = None) -> Literal["", "program", "user"]: ...
sizefrom = wm_sizefrom
@overload
def wm_state(self, newstate: None = None) -> str: ...
@overload
def wm_state(self, newstate: str) -> None: ...
state = wm_state
@overload
def wm_title(self, string: None = None) -> str: ...
@overload
def wm_title(self, string: str) -> None: ...
title = wm_title
@overload
def wm_transient(self, master: None = None) -> _tkinter.Tcl_Obj: ...
@overload
def wm_transient(self, master: Wm | _tkinter.Tcl_Obj) -> None: ...
transient = wm_transient
def wm_withdraw(self) -> None: ...
withdraw = wm_withdraw
class Tk(Misc, Wm):
master: None
def __init__(
# Make sure to keep in sync with other functions that use the same
# args.
# use `git grep screenName` to find them
self,
screenName: str | None = None,
baseName: str | None = None,
className: str = "Tk",
useTk: bool = True,
sync: bool = False,
use: str | None = None,
) -> None: ...
@overload
def configure(
self,
cnf: dict[str, Any] | None = None,
*,
background: str = ...,
bd: _ScreenUnits = ...,
bg: str = ...,
border: _ScreenUnits = ...,
borderwidth: _ScreenUnits = ...,
cursor: _Cursor = ...,
height: _ScreenUnits = ...,
highlightbackground: str = ...,
highlightcolor: str = ...,
highlightthickness: _ScreenUnits = ...,
menu: Menu = ...,
padx: _ScreenUnits = ...,
pady: _ScreenUnits = ...,
relief: _Relief = ...,
takefocus: _TakeFocusValue = ...,
width: _ScreenUnits = ...,
) -> dict[str, tuple[str, str, str, Any, Any]] | None: ...
@overload
def configure(self, cnf: str) -> tuple[str, str, str, Any, Any]: ...
config = configure
def destroy(self) -> None: ...
def readprofile(self, baseName: str, className: str) -> None: ...
report_callback_exception: Callable[[type[BaseException], BaseException, TracebackType | None], object]
# Tk has __getattr__ so that tk_instance.foo falls back to tk_instance.tk.foo
# Please keep in sync with _tkinter.TkappType.
# Some methods are intentionally missing because they are inherited from Misc instead.
def adderrorinfo(self, msg, /): ...
def call(self, command: Any, /, *args: Any) -> Any: ...
def createcommand(self, name, func, /): ...
if sys.platform != "win32":
def createfilehandler(self, file, mask, func, /): ...
def deletefilehandler(self, file, /): ...
def createtimerhandler(self, milliseconds, func, /): ...
def dooneevent(self, flags: int = ..., /): ...
def eval(self, script: str, /) -> str: ...
def evalfile(self, fileName, /): ...
def exprboolean(self, s, /): ...
def exprdouble(self, s, /): ...
def exprlong(self, s, /): ...
def exprstring(self, s, /): ...
def globalgetvar(self, *args, **kwargs): ...
def globalsetvar(self, *args, **kwargs): ...
def globalunsetvar(self, *args, **kwargs): ...
def interpaddr(self): ...
def loadtk(self) -> None: ...
def record(self, script, /): ...
if sys.version_info < (3, 11):
def split(self, arg, /): ...
def splitlist(self, arg, /): ...
def unsetvar(self, *args, **kwargs): ...
def wantobjects(self, *args, **kwargs): ...
def willdispatch(self): ...
def Tcl(screenName: str | None = None, baseName: str | None = None, className: str = "Tk", useTk: bool = False) -> Tk: ...
_InMiscTotal = TypedDict("_InMiscTotal", {"in": Misc})
_InMiscNonTotal = TypedDict("_InMiscNonTotal", {"in": Misc}, total=False)
class _PackInfo(_InMiscTotal):
# 'before' and 'after' never appear in _PackInfo
anchor: _Anchor
expand: bool
fill: Literal["none", "x", "y", "both"]
side: Literal["left", "right", "top", "bottom"]
# Paddings come out as int or tuple of int, even though any _ScreenUnits
# can be specified in pack().
ipadx: int
ipady: int
padx: int | tuple[int, int]
pady: int | tuple[int, int]
class Pack:
# _PackInfo is not the valid type for cnf because pad stuff accepts any
# _ScreenUnits instead of int only. I didn't bother to create another
# TypedDict for cnf because it appears to be a legacy thing that was
# replaced by **kwargs.
def pack_configure(
self,
cnf: Mapping[str, Any] | None = {},
*,
after: Misc = ...,
anchor: _Anchor = ...,
before: Misc = ...,
expand: bool | Literal[0, 1] = 0,
fill: Literal["none", "x", "y", "both"] = ...,
side: Literal["left", "right", "top", "bottom"] = ...,
ipadx: _ScreenUnits = ...,
ipady: _ScreenUnits = ...,
padx: _ScreenUnits | tuple[_ScreenUnits, _ScreenUnits] = ...,
pady: _ScreenUnits | tuple[_ScreenUnits, _ScreenUnits] = ...,
in_: Misc = ...,
**kw: Any, # allow keyword argument named 'in', see #4836
) -> None: ...
def pack_forget(self) -> None: ...
def pack_info(self) -> _PackInfo: ... # errors if widget hasn't been packed
pack = pack_configure
forget = pack_forget
propagate = Misc.pack_propagate
class _PlaceInfo(_InMiscNonTotal): # empty dict if widget hasn't been placed
anchor: _Anchor
bordermode: Literal["inside", "outside", "ignore"]
width: str # can be int()ed (even after e.g. widget.place(height='2.3c') or similar)
height: str # can be int()ed
x: str # can be int()ed
y: str # can be int()ed
relheight: str # can be float()ed if not empty string
relwidth: str # can be float()ed if not empty string
relx: str # can be float()ed if not empty string
rely: str # can be float()ed if not empty string
class Place:
def place_configure(
self,
cnf: Mapping[str, Any] | None = {},
*,
anchor: _Anchor = ...,
bordermode: Literal["inside", "outside", "ignore"] = ...,
width: _ScreenUnits = ...,
height: _ScreenUnits = ...,
x: _ScreenUnits = ...,
y: _ScreenUnits = ...,
# str allowed for compatibility with place_info()
relheight: str | float = ...,
relwidth: str | float = ...,
relx: str | float = ...,
rely: str | float = ...,
in_: Misc = ...,
**kw: Any, # allow keyword argument named 'in', see #4836
) -> None: ...
def place_forget(self) -> None: ...
def place_info(self) -> _PlaceInfo: ...
place = place_configure
info = place_info
class _GridInfo(_InMiscNonTotal): # empty dict if widget hasn't been gridded
column: int
columnspan: int
row: int
rowspan: int
ipadx: int
ipady: int
padx: int | tuple[int, int]
pady: int | tuple[int, int]
sticky: str # consists of letters 'n', 's', 'w', 'e', no repeats, may be empty
class Grid:
def grid_configure(
self,
cnf: Mapping[str, Any] | None = {},
*,
column: int = ...,
columnspan: int = ...,
row: int = ...,
rowspan: int = ...,
ipadx: _ScreenUnits = ...,
ipady: _ScreenUnits = ...,
padx: _ScreenUnits | tuple[_ScreenUnits, _ScreenUnits] = ...,
pady: _ScreenUnits | tuple[_ScreenUnits, _ScreenUnits] = ...,
sticky: str = ..., # consists of letters 'n', 's', 'w', 'e', may contain repeats, may be empty
in_: Misc = ...,
**kw: Any, # allow keyword argument named 'in', see #4836
) -> None: ...
def grid_forget(self) -> None: ...
def grid_remove(self) -> None: ...
def grid_info(self) -> _GridInfo: ...
grid = grid_configure
location = Misc.grid_location
size = Misc.grid_size
class BaseWidget(Misc):
master: Misc
widgetName: Incomplete
def __init__(self, master, widgetName, cnf={}, kw={}, extra=()) -> None: ...
def destroy(self) -> None: ...
# This class represents any widget except Toplevel or Tk.
class Widget(BaseWidget, Pack, Place, Grid):
# Allow bind callbacks to take e.g. Event[Label] instead of Event[Misc].
# Tk and Toplevel get notified for their child widgets' events, but other
# widgets don't.
@overload
def bind(
self: _W,
sequence: str | None = None,
func: Callable[[Event[_W]], object] | None = None,
add: Literal["", "+"] | bool | None = None,
) -> str: ...
@overload
def bind(self, sequence: str | None, func: str, add: Literal["", "+"] | bool | None = None) -> None: ...
@overload
def bind(self, *, func: str, add: Literal["", "+"] | bool | None = None) -> None: ...
class Toplevel(BaseWidget, Wm):
# Toplevel and Tk have the same options because they correspond to the same
# Tcl/Tk toplevel widget. For some reason, config and configure must be
# copy/pasted here instead of aliasing as 'config = Tk.config'.
def __init__(
self,
master: Misc | None = None,
cnf: dict[str, Any] | None = {},
*,
background: str = ...,
bd: _ScreenUnits = 0,
bg: str = ...,
border: _ScreenUnits = 0,
borderwidth: _ScreenUnits = 0,
class_: str = "Toplevel",
colormap: Literal["new", ""] | Misc = "",
container: bool = False,
cursor: _Cursor = "",
height: _ScreenUnits = 0,
highlightbackground: str = ...,
highlightcolor: str = ...,
highlightthickness: _ScreenUnits = 0,
menu: Menu = ...,
name: str = ...,
padx: _ScreenUnits = 0,
pady: _ScreenUnits = 0,
relief: _Relief = "flat",
screen: str = "", # can't be changed after creating widget
takefocus: _TakeFocusValue = 0,
use: int = ...,
visual: str | tuple[str, int] = "",
width: _ScreenUnits = 0,
) -> None: ...
@overload
def configure(
self,
cnf: dict[str, Any] | None = None,
*,
background: str = ...,
bd: _ScreenUnits = ...,
bg: str = ...,
border: _ScreenUnits = ...,
borderwidth: _ScreenUnits = ...,
cursor: _Cursor = ...,
height: _ScreenUnits = ...,
highlightbackground: str = ...,
highlightcolor: str = ...,
highlightthickness: _ScreenUnits = ...,
menu: Menu = ...,
padx: _ScreenUnits = ...,
pady: _ScreenUnits = ...,
relief: _Relief = ...,
takefocus: _TakeFocusValue = ...,
width: _ScreenUnits = ...,
) -> dict[str, tuple[str, str, str, Any, Any]] | None: ...
@overload
def configure(self, cnf: str) -> tuple[str, str, str, Any, Any]: ...
config = configure
class Button(Widget):
def __init__(
self,