-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
wraptk.py
133 lines (89 loc) · 3.71 KB
/
wraptk.py
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
import sys
from typing import Any, Callable, List, Text, Union
if sys.version_info[0] == 3:
import tkinter as tk
# import tkinter.messagebox as messagebox
from tkinter import ttk
else:
import Tkinter as tk
import ttk
# import tkMessageBox as messagebox
if False:
tk
Any, Callable, List, Text, Union
def canvas(par, *args): # {{{1
# type: (Union[tk.Tk, tk.Widget], int) -> tk.Canvas
if len(args) > 1:
return tk.Canvas(par, width=args[0], height=args[1]) # type: ignore
return tk.Canvas(par) # type: ignore # for Tk
def rectangle(inst, x1, y1, x2, y2, **kw): # {{{1
# type: (tk.Canvas, int, int, int, int, Any) -> None
inst.create_rectangle(x1, y1, x2, y2, **kw) # type: ignore # for Tk
def oval(inst, x1, y1, x2, y2, **kw): # {{{1
# type: (tk.Canvas, int, int, int, int, Any) -> None
inst.create_oval(x1, y1, x2, y2, **kw) # type: ignore # for Tk
def bind(par, ev, fn): # {{{1
# type: (tk.Widget, Text, Callable[[tk.Event], None]) -> tk.Widget
return par.bind(ev, fn) # type: ignore # for Tk
def label(par, t, **kw): # {{{1
# type: (tk.Widget, Text, Any) -> tk.Widget
return tk.Label(par, text=t, **kw) # type: ignore # for Tk
def frame(par, *args): # {{{1
# type: (Union[tk.Tk, tk.Widget], int) -> tk.Frame
if len(args) > 0:
return tk.Frame(par, height=args[0]) # type: ignore # for Tk
return tk.Frame(par) # type: ignore # for Tk
def button(par, t, **kw): # {{{1
# type: (tk.Widget, Text, Any) -> tk.Button
return tk.Button(par, text=t, **kw) # type: ignore # for Tk
def chkbtn(par, t, v): # {{{1
# type: (tk.Widget, Text, tk.IntVar) -> tk.Button
return tk.Checkbutton(par, text=t, variable=v) # type: ignore # for Tk
def scale(par, *args, **kw): # {{{1
# type: (Union[tk.Tk, tk.Widget], float, Any) -> tk.Scale
if len(args) < 1:
return tk.Scale(par) # type: ignore # for Tk
return tk.Scale(par, from_=args[0], to=args[1], # type: ignore
orient=args[2], **kw) # type: ignore # for Tk
def scale_get(scl): # {{{1
# type: (tk.Scale) -> int
return scl.get() # type: ignore
def scale_set(scl, n): # {{{1
# type: (tk.Scale, Union[int, float]) -> tk.Scale
scl.set(n) # type: ignore
return scl
def entry(par, *args): # {{{1
# type: (Union[tk.Tk, tk.Widget], int) -> tk.Entry
if len(args) > 0:
return tk.Entry(par, width=args[0]) # type: ignore # for Tk
return tk.Entry(par) # type: ignore # for Tk
def text(par, *args): # {{{1
# type: (Union[tk.Tk, tk.Widget], int) -> tk.Text
if len(args) > 0:
return tk.Text(par, height=args[0]) # type: ignore # for Tk
return tk.Text(par) # type: ignore # for Tk
def text_insert(txt, n, t): # {{{1
# type: (Union[tk.Text, tk.Entry], int, Text) -> None
txt.insert(n, t) # type: ignore # for Tk
def text_delete(txt, n1, n2): # {{{1
# type: (tk.Text, Text, Text) -> None
txt.delete(n1, n2) # type: ignore # for Tk
def enty_delete(txt, n1, n2): # {{{1
# type: (tk.Entry, Union[int, Text], Text) -> None
txt.delete(n1, n2) # type: ignore # for Tk
def cmbbox(par, items, cur): # {{{1
# type: (tk.Widget, List[Text], int) -> ttk.Combobox
ret = ttk.Combobox(par, values=items) # type: ignore # for Tk
ret.current(cur) # type: ignore
return ret # type: ignore
def var_int(): # {{{1
# type: () -> tk.IntVar
return tk.IntVar() # type: ignore # for Tk
def set_int(_var, n): # {{{1
# type: (tk.IntVar, int) -> None
_var.set(n) # type: ignore # for Tk
def root_quit(root): # {{{1
# type: (tk.Tk) -> None
root.quit() # type: ignore # for Tk
# end of file {{{1
# vi: ft=python:et:fdm=marker:nowrap:tw=80