Linux ip-148-66-134-25.ip.secureserver.net 3.10.0-1160.119.1.el7.tuxcare.els11.x86_64 #1 SMP Sun Nov 3 09:06:59 UTC 2024 x86_64
Apache
: 148.66.134.25 | : 3.145.105.149
66 Domain
8.0.30
amvm
www.github.com/MadExploits
Terminal
AUTO ROOT
Adminer
Backdoor Destroyer
Linux Exploit
Lock Shell
Lock File
Create User
CREATE RDP
PHP Mailer
BACKCONNECT
UNLOCK SHELL
HASH IDENTIFIER
CPANEL RESET
BLACK DEFEND!
README
+ Create Folder
+ Create File
/
usr /
share /
doc /
python-docs-2.7.5 /
html /
library /
[ HOME SHELL ]
Name
Size
Permission
Action
2to3.html
49.27
KB
-rw-r--r--
__builtin__.html
10.26
KB
-rw-r--r--
__future__.html
13.79
KB
-rw-r--r--
__main__.html
7.05
KB
-rw-r--r--
_winreg.html
59.21
KB
-rw-r--r--
abc.html
23.9
KB
-rw-r--r--
aepack.html
13.16
KB
-rw-r--r--
aetools.html
14.91
KB
-rw-r--r--
aetypes.html
18.88
KB
-rw-r--r--
aifc.html
22.4
KB
-rw-r--r--
al.html
17.34
KB
-rw-r--r--
allos.html
33.72
KB
-rw-r--r--
anydbm.html
16.33
KB
-rw-r--r--
archiving.html
9.26
KB
-rw-r--r--
argparse.html
237.62
KB
-rw-r--r--
array.html
29.29
KB
-rw-r--r--
ast.html
34.98
KB
-rw-r--r--
asynchat.html
31.43
KB
-rw-r--r--
asyncore.html
36.51
KB
-rw-r--r--
atexit.html
16.8
KB
-rw-r--r--
audioop.html
31.36
KB
-rw-r--r--
autogil.html
8.19
KB
-rw-r--r--
base64.html
19.67
KB
-rw-r--r--
basehttpserver.html
34.04
KB
-rw-r--r--
bastion.html
11.04
KB
-rw-r--r--
bdb.html
36.68
KB
-rw-r--r--
binascii.html
20.67
KB
-rw-r--r--
binhex.html
10.58
KB
-rw-r--r--
bisect.html
23.24
KB
-rw-r--r--
bsddb.html
26.43
KB
-rw-r--r--
bz2.html
26.08
KB
-rw-r--r--
calendar.html
37.79
KB
-rw-r--r--
carbon.html
48.94
KB
-rw-r--r--
cd.html
27.96
KB
-rw-r--r--
cgi.html
49.92
KB
-rw-r--r--
cgihttpserver.html
13.1
KB
-rw-r--r--
cgitb.html
11.41
KB
-rw-r--r--
chunk.html
14.66
KB
-rw-r--r--
cmath.html
25.63
KB
-rw-r--r--
cmd.html
26.09
KB
-rw-r--r--
code.html
24.58
KB
-rw-r--r--
codecs.html
100.64
KB
-rw-r--r--
codeop.html
14.84
KB
-rw-r--r--
collections.html
133.96
KB
-rw-r--r--
colorpicker.html
7.52
KB
-rw-r--r--
colorsys.html
11.04
KB
-rw-r--r--
commands.html
14.36
KB
-rw-r--r--
compileall.html
16.83
KB
-rw-r--r--
compiler.html
67.75
KB
-rw-r--r--
configparser.html
62.13
KB
-rw-r--r--
constants.html
12.83
KB
-rw-r--r--
contextlib.html
19.39
KB
-rw-r--r--
cookie.html
39.07
KB
-rw-r--r--
cookielib.html
83.82
KB
-rw-r--r--
copy.html
12.19
KB
-rw-r--r--
copy_reg.html
13.76
KB
-rw-r--r--
crypt.html
10.04
KB
-rw-r--r--
crypto.html
7.59
KB
-rw-r--r--
csv.html
67.37
KB
-rw-r--r--
ctypes.html
238.78
KB
-rw-r--r--
curses.ascii.html
22.29
KB
-rw-r--r--
curses.html
146.63
KB
-rw-r--r--
curses.panel.html
14.39
KB
-rw-r--r--
custominterp.html
7.62
KB
-rw-r--r--
datatypes.html
16.84
KB
-rw-r--r--
datetime.html
226.59
KB
-rw-r--r--
dbhash.html
15.48
KB
-rw-r--r--
dbm.html
12.07
KB
-rw-r--r--
debug.html
10.15
KB
-rw-r--r--
decimal.html
194.44
KB
-rw-r--r--
development.html
14.17
KB
-rw-r--r--
difflib.html
84.83
KB
-rw-r--r--
dircache.html
11.41
KB
-rw-r--r--
dis.html
69.95
KB
-rw-r--r--
distutils.html
8.05
KB
-rw-r--r--
dl.html
16.33
KB
-rw-r--r--
doctest.html
165.54
KB
-rw-r--r--
docxmlrpcserver.html
16.43
KB
-rw-r--r--
dumbdbm.html
14.02
KB
-rw-r--r--
dummy_thread.html
9.43
KB
-rw-r--r--
dummy_threading.html
8.37
KB
-rw-r--r--
easydialogs.html
30.55
KB
-rw-r--r--
email-examples.html
45.65
KB
-rw-r--r--
email.charset.html
26.8
KB
-rw-r--r--
email.encoders.html
11.86
KB
-rw-r--r--
email.errors.html
15.77
KB
-rw-r--r--
email.generator.html
20.77
KB
-rw-r--r--
email.header.html
26.92
KB
-rw-r--r--
email.html
44.24
KB
-rw-r--r--
email.iterators.html
11.52
KB
-rw-r--r--
email.message.html
63.16
KB
-rw-r--r--
email.mime.html
27.93
KB
-rw-r--r--
email.parser.html
30.45
KB
-rw-r--r--
email.util.html
24.46
KB
-rw-r--r--
errno.html
37.99
KB
-rw-r--r--
exceptions.html
56.13
KB
-rw-r--r--
fcntl.html
22.67
KB
-rw-r--r--
filecmp.html
22.3
KB
-rw-r--r--
fileformats.html
9.14
KB
-rw-r--r--
fileinput.html
24.28
KB
-rw-r--r--
filesys.html
10.2
KB
-rw-r--r--
fl.html
49.92
KB
-rw-r--r--
fm.html
11.91
KB
-rw-r--r--
fnmatch.html
14.58
KB
-rw-r--r--
formatter.html
34.06
KB
-rw-r--r--
fpectl.html
16.01
KB
-rw-r--r--
fpformat.html
10.59
KB
-rw-r--r--
fractions.html
22.61
KB
-rw-r--r--
framework.html
33.34
KB
-rw-r--r--
frameworks.html
7.14
KB
-rw-r--r--
ftplib.html
43.99
KB
-rw-r--r--
functions.html
183.14
KB
-rw-r--r--
functools.html
27.17
KB
-rw-r--r--
future_builtins.html
13.04
KB
-rw-r--r--
gc.html
25.75
KB
-rw-r--r--
gdbm.html
15.96
KB
-rw-r--r--
gensuitemodule.html
11.51
KB
-rw-r--r--
getopt.html
23.66
KB
-rw-r--r--
getpass.html
10.65
KB
-rw-r--r--
gettext.html
78.76
KB
-rw-r--r--
gl.html
22.09
KB
-rw-r--r--
glob.html
13.26
KB
-rw-r--r--
grp.html
10.49
KB
-rw-r--r--
gzip.html
18.99
KB
-rw-r--r--
hashlib.html
18.2
KB
-rw-r--r--
heapq.html
31.61
KB
-rw-r--r--
hmac.html
10.46
KB
-rw-r--r--
hotshot.html
18.65
KB
-rw-r--r--
htmllib.html
25.32
KB
-rw-r--r--
htmlparser.html
39.11
KB
-rw-r--r--
httplib.html
62.95
KB
-rw-r--r--
i18n.html
9.52
KB
-rw-r--r--
ic.html
17.17
KB
-rw-r--r--
idle.html
20.9
KB
-rw-r--r--
imageop.html
14.76
KB
-rw-r--r--
imaplib.html
51.99
KB
-rw-r--r--
imgfile.html
11.71
KB
-rw-r--r--
imghdr.html
11.3
KB
-rw-r--r--
imp.html
34.34
KB
-rw-r--r--
importlib.html
8.26
KB
-rw-r--r--
imputil.html
31.81
KB
-rw-r--r--
index.html
72.78
KB
-rw-r--r--
inspect.html
50.71
KB
-rw-r--r--
internet.html
24.87
KB
-rw-r--r--
intro.html
8.93
KB
-rw-r--r--
io.html
98.13
KB
-rw-r--r--
ipc.html
13.41
KB
-rw-r--r--
itertools.html
115.91
KB
-rw-r--r--
jpeg.html
12.74
KB
-rw-r--r--
json.html
67.04
KB
-rw-r--r--
keyword.html
7.68
KB
-rw-r--r--
language.html
11.03
KB
-rw-r--r--
linecache.html
10.59
KB
-rw-r--r--
locale.html
55.14
KB
-rw-r--r--
logging.config.html
63.36
KB
-rw-r--r--
logging.handlers.html
69.64
KB
-rw-r--r--
logging.html
95.64
KB
-rw-r--r--
mac.html
21.79
KB
-rw-r--r--
macos.html
14.76
KB
-rw-r--r--
macosa.html
12.96
KB
-rw-r--r--
macostools.html
15.52
KB
-rw-r--r--
macpath.html
7.76
KB
-rw-r--r--
mailbox.html
156.75
KB
-rw-r--r--
mailcap.html
13.21
KB
-rw-r--r--
markup.html
18.77
KB
-rw-r--r--
marshal.html
17.98
KB
-rw-r--r--
math.html
39.24
KB
-rw-r--r--
md5.html
13.97
KB
-rw-r--r--
mhlib.html
21.54
KB
-rw-r--r--
mimetools.html
19.25
KB
-rw-r--r--
mimetypes.html
28.39
KB
-rw-r--r--
mimewriter.html
15.02
KB
-rw-r--r--
mimify.html
13.36
KB
-rw-r--r--
miniaeframe.html
12.2
KB
-rw-r--r--
misc.html
6.87
KB
-rw-r--r--
mm.html
9.03
KB
-rw-r--r--
mmap.html
28.36
KB
-rw-r--r--
modulefinder.html
15.31
KB
-rw-r--r--
modules.html
8.46
KB
-rw-r--r--
msilib.html
52.43
KB
-rw-r--r--
msvcrt.html
19.37
KB
-rw-r--r--
multifile.html
24.3
KB
-rw-r--r--
multiprocessing.html
365.71
KB
-rw-r--r--
mutex.html
11.23
KB
-rw-r--r--
netdata.html
16.98
KB
-rw-r--r--
netrc.html
12.3
KB
-rw-r--r--
new.html
12.12
KB
-rw-r--r--
nis.html
10.64
KB
-rw-r--r--
nntplib.html
41.92
KB
-rw-r--r--
numbers.html
37.75
KB
-rw-r--r--
numeric.html
13.55
KB
-rw-r--r--
operator.html
82
KB
-rw-r--r--
optparse.html
222.56
KB
-rw-r--r--
os.html
214.25
KB
-rw-r--r--
os.path.html
38.34
KB
-rw-r--r--
ossaudiodev.html
41.5
KB
-rw-r--r--
othergui.html
9.08
KB
-rw-r--r--
parser.html
39.36
KB
-rw-r--r--
pdb.html
33.96
KB
-rw-r--r--
persistence.html
14.87
KB
-rw-r--r--
pickle.html
102.27
KB
-rw-r--r--
pickletools.html
10.63
KB
-rw-r--r--
pipes.html
18.01
KB
-rw-r--r--
pkgutil.html
25.11
KB
-rw-r--r--
platform.html
28.37
KB
-rw-r--r--
plistlib.html
17.03
KB
-rw-r--r--
popen2.html
25.43
KB
-rw-r--r--
poplib.html
22.32
KB
-rw-r--r--
posix.html
14.41
KB
-rw-r--r--
posixfile.html
19.76
KB
-rw-r--r--
pprint.html
29.92
KB
-rw-r--r--
profile.html
63.56
KB
-rw-r--r--
pty.html
9.48
KB
-rw-r--r--
pwd.html
11.43
KB
-rw-r--r--
py_compile.html
11.12
KB
-rw-r--r--
pyclbr.html
14.71
KB
-rw-r--r--
pydoc.html
11.48
KB
-rw-r--r--
pyexpat.html
71.53
KB
-rw-r--r--
python.html
12.27
KB
-rw-r--r--
queue.html
24.22
KB
-rw-r--r--
quopri.html
11.9
KB
-rw-r--r--
random.html
37.83
KB
-rw-r--r--
re.html
134.74
KB
-rw-r--r--
readline.html
28.24
KB
-rw-r--r--
repr.html
20.43
KB
-rw-r--r--
resource.html
26.48
KB
-rw-r--r--
restricted.html
11.65
KB
-rw-r--r--
rexec.html
37.41
KB
-rw-r--r--
rfc822.html
42.22
KB
-rw-r--r--
rlcompleter.html
13.51
KB
-rw-r--r--
robotparser.html
12.27
KB
-rw-r--r--
runpy.html
19.34
KB
-rw-r--r--
sched.html
18.54
KB
-rw-r--r--
scrolledtext.html
9.32
KB
-rw-r--r--
select.html
39.67
KB
-rw-r--r--
sets.html
36.92
KB
-rw-r--r--
sgi.html
9.71
KB
-rw-r--r--
sgmllib.html
30.77
KB
-rw-r--r--
sha.html
12.09
KB
-rw-r--r--
shelve.html
27.02
KB
-rw-r--r--
shlex.html
32.1
KB
-rw-r--r--
shutil.html
40.22
KB
-rw-r--r--
signal.html
31.14
KB
-rw-r--r--
simplehttpserver.html
18.41
KB
-rw-r--r--
simplexmlrpcserver.html
31.39
KB
-rw-r--r--
site.html
23.64
KB
-rw-r--r--
smtpd.html
12.46
KB
-rw-r--r--
smtplib.html
42.13
KB
-rw-r--r--
sndhdr.html
10.02
KB
-rw-r--r--
socket.html
106.34
KB
-rw-r--r--
socketserver.html
59.83
KB
-rw-r--r--
someos.html
15.11
KB
-rw-r--r--
spwd.html
10.33
KB
-rw-r--r--
sqlite3.html
139.5
KB
-rw-r--r--
ssl.html
65.62
KB
-rw-r--r--
stat.html
32.31
KB
-rw-r--r--
statvfs.html
10.6
KB
-rw-r--r--
stdtypes.html
260.4
KB
-rw-r--r--
string.html
106.65
KB
-rw-r--r--
stringio.html
18.81
KB
-rw-r--r--
stringprep.html
16.13
KB
-rw-r--r--
strings.html
14.93
KB
-rw-r--r--
struct.html
40.88
KB
-rw-r--r--
subprocess.html
84.91
KB
-rw-r--r--
sun.html
6.84
KB
-rw-r--r--
sunau.html
27.1
KB
-rw-r--r--
sunaudio.html
17.79
KB
-rw-r--r--
symbol.html
7.66
KB
-rw-r--r--
symtable.html
22.94
KB
-rw-r--r--
sys.html
98.7
KB
-rw-r--r--
sysconfig.html
23.84
KB
-rw-r--r--
syslog.html
17.92
KB
-rw-r--r--
tabnanny.html
10.63
KB
-rw-r--r--
tarfile.html
78.68
KB
-rw-r--r--
telnetlib.html
25.48
KB
-rw-r--r--
tempfile.html
29.42
KB
-rw-r--r--
termios.html
16.01
KB
-rw-r--r--
test.html
52.62
KB
-rw-r--r--
textwrap.html
27.25
KB
-rw-r--r--
thread.html
20.47
KB
-rw-r--r--
threading.html
76.69
KB
-rw-r--r--
time.html
56.93
KB
-rw-r--r--
timeit.html
36.27
KB
-rw-r--r--
tix.html
46.96
KB
-rw-r--r--
tk.html
23.64
KB
-rw-r--r--
tkinter.html
67.67
KB
-rw-r--r--
token.html
19.62
KB
-rw-r--r--
tokenize.html
18.45
KB
-rw-r--r--
trace.html
25.54
KB
-rw-r--r--
traceback.html
33.44
KB
-rw-r--r--
ttk.html
101.75
KB
-rw-r--r--
tty.html
9.06
KB
-rw-r--r--
turtle.html
211.74
KB
-rw-r--r--
types.html
27.59
KB
-rw-r--r--
undoc.html
23.16
KB
-rw-r--r--
unicodedata.html
18.55
KB
-rw-r--r--
unittest.html
202.85
KB
-rw-r--r--
unix.html
10.55
KB
-rw-r--r--
urllib.html
58.68
KB
-rw-r--r--
urllib2.html
100.58
KB
-rw-r--r--
urlparse.html
40.41
KB
-rw-r--r--
user.html
11.83
KB
-rw-r--r--
userdict.html
29.73
KB
-rw-r--r--
uu.html
11.03
KB
-rw-r--r--
uuid.html
28.19
KB
-rw-r--r--
warnings.html
46.6
KB
-rw-r--r--
wave.html
22.22
KB
-rw-r--r--
weakref.html
36.52
KB
-rw-r--r--
webbrowser.html
23.07
KB
-rw-r--r--
whichdb.html
8.85
KB
-rw-r--r--
windows.html
9.33
KB
-rw-r--r--
winsound.html
18.75
KB
-rw-r--r--
wsgiref.html
81.04
KB
-rw-r--r--
xdrlib.html
29.94
KB
-rw-r--r--
xml.dom.html
89.04
KB
-rw-r--r--
xml.dom.minidom.html
40.42
KB
-rw-r--r--
xml.dom.pulldom.html
12.71
KB
-rw-r--r--
xml.etree.elementtree.html
93.22
KB
-rw-r--r--
xml.html
16.49
KB
-rw-r--r--
xml.sax.handler.html
38.63
KB
-rw-r--r--
xml.sax.html
20.22
KB
-rw-r--r--
xml.sax.reader.html
39.09
KB
-rw-r--r--
xml.sax.utils.html
14.26
KB
-rw-r--r--
xmlrpclib.html
60.79
KB
-rw-r--r--
zipfile.html
53.14
KB
-rw-r--r--
zipimport.html
20.42
KB
-rw-r--r--
zlib.html
25.46
KB
-rw-r--r--
Delete
Unzip
Zip
${this.title}
Close
Code Editor : tkinter.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>24.1. Tkinter — Python interface to Tcl/Tk — Python 2.7.5 documentation</title> <link rel="stylesheet" href="../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../', VERSION: '2.7.5', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 2.7.5 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="top" title="Python 2.7.5 documentation" href="../index.html" /> <link rel="up" title="24. Graphical User Interfaces with Tk" href="tk.html" /> <link rel="next" title="24.2. ttk — Tk themed widgets" href="ttk.html" /> <link rel="prev" title="24. Graphical User Interfaces with Tk" href="tk.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head> <body> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="ttk.html" title="24.2. ttk — Tk themed widgets" accesskey="N">next</a> |</li> <li class="right" > <a href="tk.html" title="24. Graphical User Interfaces with Tk" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="tk.html" accesskey="U">24. Graphical User Interfaces with Tk</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-Tkinter"> <span id="tkinter-python-interface-to-tcl-tk"></span><h1>24.1. <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> — Python interface to Tcl/Tk<a class="headerlink" href="#module-Tkinter" title="Permalink to this headline">¶</a></h1> <p>The <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> module (“Tk interface”) is the standard Python interface to the Tk GUI toolkit. Both Tk and <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> are available on most Unix platforms, as well as on Windows systems. (Tk itself is not part of Python; it is maintained at ActiveState.)</p> <div class="admonition note"> <p class="first admonition-title">Note</p> <p class="last"><a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> has been renamed to <tt class="xref py py-mod docutils literal"><span class="pre">tkinter</span></tt> in Python 3. The <a class="reference internal" href="../glossary.html#term-to3"><em class="xref std std-term">2to3</em></a> tool will automatically adapt imports when converting your sources to Python 3.</p> </div> <div class="admonition-see-also admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt><a class="reference external" href="http://www.python.org/topics/tkinter/">Python Tkinter Resources</a></dt> <dd>The Python Tkinter Topic Guide provides a great deal of information on using Tk from Python and links to other sources of information on Tk.</dd> <dt><a class="reference external" href="http://www.tkdocs.com/">TKDocs</a></dt> <dd>Extensive tutorial plus friendlier widget pages for some of the widgets.</dd> <dt><a class="reference external" href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/">Tkinter reference: a GUI for Python</a></dt> <dd>On-line reference material.</dd> <dt><a class="reference external" href="http://effbot.org/tkinterbook/">Tkinter docs from effbot</a></dt> <dd>Online reference for tkinter supported by effbot.org.</dd> <dt><a class="reference external" href="http://www.tcl.tk/man/tcl8.5/">Tcl/Tk manual</a></dt> <dd>Official manual for the latest tcl/tk version.</dd> <dt><a class="reference external" href="http://www.amazon.com/Programming-Python-Mark-Lutz/dp/0596158106/">Programming Python</a></dt> <dd>Book by Mark Lutz, has excellent coverage of Tkinter.</dd> <dt><a class="reference external" href="http://www.amazon.com/Modern-Tkinter-Python-Developers-ebook/dp/B0071QDNLO/">Modern Tkinter for Busy Python Developers</a></dt> <dd>Book by Mark Rozerman about building attractive and modern graphical user interfaces with Python and Tkinter.</dd> <dt><a class="reference external" href="http://www.pythonware.com/library/an-introduction-to-tkinter.htm">An Introduction to Tkinter</a></dt> <dd>Fredrik Lundh’s on-line reference material.</dd> <dt><a class="reference external" href="http://www.amazon.com/exec/obidos/ASIN/1884777813">Python and Tkinter Programming</a></dt> <dd>The book by John Grayson (ISBN 1-884777-81-3).</dd> </dl> </div> <div class="section" id="tkinter-modules"> <h2>24.1.1. Tkinter Modules<a class="headerlink" href="#tkinter-modules" title="Permalink to this headline">¶</a></h2> <p>Most of the time, the <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> module is all you really need, but a number of additional modules are available as well. The Tk interface is located in a binary module named <tt class="xref py py-mod docutils literal"><span class="pre">_tkinter</span></tt>. This module contains the low-level interface to Tk, and should never be used directly by application programmers. It is usually a shared library (or DLL), but might in some cases be statically linked with the Python interpreter.</p> <p>In addition to the Tk interface module, <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> includes a number of Python modules. The two most important modules are the <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> module itself, and a module called <tt class="xref py py-mod docutils literal"><span class="pre">Tkconstants</span></tt>. The former automatically imports the latter, so to use Tkinter, all you need to do is to import one module:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">Tkinter</span> </pre></div> </div> <p>Or, more often:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Tkinter</span> <span class="kn">import</span> <span class="o">*</span> </pre></div> </div> <dl class="class"> <dt id="Tkinter.Tk"> <em class="property">class </em><tt class="descclassname">Tkinter.</tt><tt class="descname">Tk</tt><big>(</big><em>screenName=None</em>, <em>baseName=None</em>, <em>className='Tk'</em>, <em>useTk=1</em><big>)</big><a class="headerlink" href="#Tkinter.Tk" title="Permalink to this definition">¶</a></dt> <dd><p>The <a class="reference internal" href="#Tkinter.Tk" title="Tkinter.Tk"><tt class="xref py py-class docutils literal"><span class="pre">Tk</span></tt></a> class is instantiated without arguments. This creates a toplevel widget of Tk which usually is the main window of an application. Each instance has its own associated Tcl interpreter.</p> <p class="versionchanged"> <span class="versionmodified">Changed in version 2.4: </span>The <em>useTk</em> parameter was added.</p> </dd></dl> <dl class="function"> <dt id="Tkinter.Tcl"> <tt class="descclassname">Tkinter.</tt><tt class="descname">Tcl</tt><big>(</big><em>screenName=None</em>, <em>baseName=None</em>, <em>className='Tk'</em>, <em>useTk=0</em><big>)</big><a class="headerlink" href="#Tkinter.Tcl" title="Permalink to this definition">¶</a></dt> <dd><p>The <a class="reference internal" href="#Tkinter.Tcl" title="Tkinter.Tcl"><tt class="xref py py-func docutils literal"><span class="pre">Tcl()</span></tt></a> function is a factory function which creates an object much like that created by the <a class="reference internal" href="#Tkinter.Tk" title="Tkinter.Tk"><tt class="xref py py-class docutils literal"><span class="pre">Tk</span></tt></a> class, except that it does not initialize the Tk subsystem. This is most often useful when driving the Tcl interpreter in an environment where one doesn’t want to create extraneous toplevel windows, or where one cannot (such as Unix/Linux systems without an X server). An object created by the <a class="reference internal" href="#Tkinter.Tcl" title="Tkinter.Tcl"><tt class="xref py py-func docutils literal"><span class="pre">Tcl()</span></tt></a> object can have a Toplevel window created (and the Tk subsystem initialized) by calling its <tt class="xref py py-meth docutils literal"><span class="pre">loadtk()</span></tt> method.</p> <p class="versionadded"> <span class="versionmodified">New in version 2.4.</span></p> </dd></dl> <p>Other modules that provide Tk support include:</p> <dl class="docutils"> <dt><a class="reference internal" href="scrolledtext.html#module-ScrolledText" title="ScrolledText: Text widget with a vertical scroll bar. (Tk)"><tt class="xref py py-mod docutils literal"><span class="pre">ScrolledText</span></tt></a></dt> <dd>Text widget with a vertical scroll bar built in.</dd> <dt><tt class="xref py py-mod docutils literal"><span class="pre">tkColorChooser</span></tt></dt> <dd>Dialog to let the user choose a color.</dd> <dt><tt class="xref py py-mod docutils literal"><span class="pre">tkCommonDialog</span></tt></dt> <dd>Base class for the dialogs defined in the other modules listed here.</dd> <dt><tt class="xref py py-mod docutils literal"><span class="pre">tkFileDialog</span></tt></dt> <dd>Common dialogs to allow the user to specify a file to open or save.</dd> <dt><tt class="xref py py-mod docutils literal"><span class="pre">tkFont</span></tt></dt> <dd>Utilities to help work with fonts.</dd> <dt><tt class="xref py py-mod docutils literal"><span class="pre">tkMessageBox</span></tt></dt> <dd>Access to standard Tk dialog boxes.</dd> <dt><tt class="xref py py-mod docutils literal"><span class="pre">tkSimpleDialog</span></tt></dt> <dd>Basic dialogs and convenience functions.</dd> <dt><tt class="xref py py-mod docutils literal"><span class="pre">Tkdnd</span></tt></dt> <dd>Drag-and-drop support for <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a>. This is experimental and should become deprecated when it is replaced with the Tk DND.</dd> <dt><a class="reference internal" href="turtle.html#module-turtle" title="turtle: Turtle graphics for Tk"><tt class="xref py py-mod docutils literal"><span class="pre">turtle</span></tt></a></dt> <dd>Turtle graphics in a Tk window.</dd> </dl> <p>These have been renamed as well in Python 3; they were all made submodules of the new <tt class="docutils literal"><span class="pre">tkinter</span></tt> package.</p> </div> <div class="section" id="tkinter-life-preserver"> <h2>24.1.2. Tkinter Life Preserver<a class="headerlink" href="#tkinter-life-preserver" title="Permalink to this headline">¶</a></h2> <p>This section is not designed to be an exhaustive tutorial on either Tk or Tkinter. Rather, it is intended as a stop gap, providing some introductory orientation on the system.</p> <p>Credits:</p> <ul class="simple"> <li>Tkinter was written by Steen Lumholt and Guido van Rossum.</li> <li>Tk was written by John Ousterhout while at Berkeley.</li> <li>This Life Preserver was written by Matt Conway at the University of Virginia.</li> <li>The html rendering, and some liberal editing, was produced from a FrameMaker version by Ken Manheimer.</li> <li>Fredrik Lundh elaborated and revised the class interface descriptions, to get them current with Tk 4.2.</li> <li>Mike Clarkson converted the documentation to LaTeX, and compiled the User Interface chapter of the reference manual.</li> </ul> <div class="section" id="how-to-use-this-section"> <h3>24.1.2.1. How To Use This Section<a class="headerlink" href="#how-to-use-this-section" title="Permalink to this headline">¶</a></h3> <p>This section is designed in two parts: the first half (roughly) covers background material, while the second half can be taken to the keyboard as a handy reference.</p> <p>When trying to answer questions of the form “how do I do blah”, it is often best to find out how to do”blah” in straight Tk, and then convert this back into the corresponding <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> call. Python programmers can often guess at the correct Python command by looking at the Tk documentation. This means that in order to use Tkinter, you will have to know a little bit about Tk. This document can’t fulfill that role, so the best we can do is point you to the best documentation that exists. Here are some hints:</p> <ul class="simple"> <li>The authors strongly suggest getting a copy of the Tk man pages. Specifically, the man pages in the <tt class="docutils literal"><span class="pre">mann</span></tt> directory are most useful. The <tt class="docutils literal"><span class="pre">man3</span></tt> man pages describe the C interface to the Tk library and thus are not especially helpful for script writers.</li> <li>Addison-Wesley publishes a book called Tcl and the Tk Toolkit by John Ousterhout (ISBN 0-201-63337-X) which is a good introduction to Tcl and Tk for the novice. The book is not exhaustive, and for many details it defers to the man pages.</li> <li><tt class="file docutils literal"><span class="pre">Tkinter.py</span></tt> is a last resort for most, but can be a good place to go when nothing else makes sense.</li> </ul> <div class="admonition-see-also admonition seealso"> <p class="first admonition-title">See also</p> <dl class="last docutils"> <dt><a class="reference external" href="http://tcl.activestate.com/">ActiveState Tcl Home Page</a></dt> <dd>The Tk/Tcl development is largely taking place at ActiveState.</dd> <dt><a class="reference external" href="http://www.amazon.com/exec/obidos/ASIN/020163337X">Tcl and the Tk Toolkit</a></dt> <dd>The book by John Ousterhout, the inventor of Tcl .</dd> <dt><a class="reference external" href="http://www.amazon.com/exec/obidos/ASIN/0130220280">Practical Programming in Tcl and Tk</a></dt> <dd>Brent Welch’s encyclopedic book.</dd> </dl> </div> </div> <div class="section" id="a-simple-hello-world-program"> <h3>24.1.2.2. A Simple Hello World Program<a class="headerlink" href="#a-simple-hello-world-program" title="Permalink to this headline">¶</a></h3> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Tkinter</span> <span class="kn">import</span> <span class="o">*</span> <span class="k">class</span> <span class="nc">Application</span><span class="p">(</span><span class="n">Frame</span><span class="p">):</span> <span class="k">def</span> <span class="nf">say_hi</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="k">print</span> <span class="s">"hi there, everyone!"</span> <span class="k">def</span> <span class="nf">createWidgets</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> <span class="bp">self</span><span class="o">.</span><span class="n">QUIT</span> <span class="o">=</span> <span class="n">Button</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">QUIT</span><span class="p">[</span><span class="s">"text"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"QUIT"</span> <span class="bp">self</span><span class="o">.</span><span class="n">QUIT</span><span class="p">[</span><span class="s">"fg"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"red"</span> <span class="bp">self</span><span class="o">.</span><span class="n">QUIT</span><span class="p">[</span><span class="s">"command"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">quit</span> <span class="bp">self</span><span class="o">.</span><span class="n">QUIT</span><span class="o">.</span><span class="n">pack</span><span class="p">({</span><span class="s">"side"</span><span class="p">:</span> <span class="s">"left"</span><span class="p">})</span> <span class="bp">self</span><span class="o">.</span><span class="n">hi_there</span> <span class="o">=</span> <span class="n">Button</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">hi_there</span><span class="p">[</span><span class="s">"text"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"Hello"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">hi_there</span><span class="p">[</span><span class="s">"command"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">say_hi</span> <span class="bp">self</span><span class="o">.</span><span class="n">hi_there</span><span class="o">.</span><span class="n">pack</span><span class="p">({</span><span class="s">"side"</span><span class="p">:</span> <span class="s">"left"</span><span class="p">})</span> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">master</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> <span class="n">Frame</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">master</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span> <span class="bp">self</span><span class="o">.</span><span class="n">createWidgets</span><span class="p">()</span> <span class="n">root</span> <span class="o">=</span> <span class="n">Tk</span><span class="p">()</span> <span class="n">app</span> <span class="o">=</span> <span class="n">Application</span><span class="p">(</span><span class="n">master</span><span class="o">=</span><span class="n">root</span><span class="p">)</span> <span class="n">app</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span> <span class="n">root</span><span class="o">.</span><span class="n">destroy</span><span class="p">()</span> </pre></div> </div> </div> </div> <div class="section" id="a-very-quick-look-at-tcl-tk"> <h2>24.1.3. A (Very) Quick Look at Tcl/Tk<a class="headerlink" href="#a-very-quick-look-at-tcl-tk" title="Permalink to this headline">¶</a></h2> <p>The class hierarchy looks complicated, but in actual practice, application programmers almost always refer to the classes at the very bottom of the hierarchy.</p> <p>Notes:</p> <ul class="simple"> <li>These classes are provided for the purposes of organizing certain functions under one namespace. They aren’t meant to be instantiated independently.</li> <li>The <a class="reference internal" href="#Tkinter.Tk" title="Tkinter.Tk"><tt class="xref py py-class docutils literal"><span class="pre">Tk</span></tt></a> class is meant to be instantiated only once in an application. Application programmers need not instantiate one explicitly, the system creates one whenever any of the other classes are instantiated.</li> <li>The <tt class="xref py py-class docutils literal"><span class="pre">Widget</span></tt> class is not meant to be instantiated, it is meant only for subclassing to make “real” widgets (in C++, this is called an ‘abstract class’).</li> </ul> <p>To make use of this reference material, there will be times when you will need to know how to read short passages of Tk and how to identify the various parts of a Tk command. (See section <a class="reference internal" href="#tkinter-basic-mapping"><em>Mapping Basic Tk into Tkinter</em></a> for the <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> equivalents of what’s below.)</p> <p>Tk scripts are Tcl programs. Like all Tcl programs, Tk scripts are just lists of tokens separated by spaces. A Tk widget is just its <em>class</em>, the <em>options</em> that help configure it, and the <em>actions</em> that make it do useful things.</p> <p>To make a widget in Tk, the command is always of the form:</p> <div class="highlight-python"><pre>classCommand newPathname options</pre> </div> <dl class="docutils"> <dt><em>classCommand</em></dt> <dd>denotes which kind of widget to make (a button, a label, a menu...)</dd> <dt><em>newPathname</em></dt> <dd>is the new name for this widget. All names in Tk must be unique. To help enforce this, widgets in Tk are named with <em>pathnames</em>, just like files in a file system. The top level widget, the <em>root</em>, is called <tt class="docutils literal"><span class="pre">.</span></tt> (period) and children are delimited by more periods. For example, <tt class="docutils literal"><span class="pre">.myApp.controlPanel.okButton</span></tt> might be the name of a widget.</dd> <dt><em>options</em></dt> <dd>configure the widget’s appearance and in some cases, its behavior. The options come in the form of a list of flags and values. Flags are preceded by a ‘-‘, like Unix shell command flags, and values are put in quotes if they are more than one word.</dd> </dl> <p>For example:</p> <div class="highlight-python"><pre>button .fred -fg red -text "hi there" ^ ^ \_____________________/ | | | class new options command widget (-opt val -opt val ...)</pre> </div> <p>Once created, the pathname to the widget becomes a new command. This new <em>widget command</em> is the programmer’s handle for getting the new widget to perform some <em>action</em>. In C, you’d express this as someAction(fred, someOptions), in C++, you would express this as fred.someAction(someOptions), and in Tk, you say:</p> <div class="highlight-python"><pre>.fred someAction someOptions</pre> </div> <p>Note that the object name, <tt class="docutils literal"><span class="pre">.fred</span></tt>, starts with a dot.</p> <p>As you’d expect, the legal values for <em>someAction</em> will depend on the widget’s class: <tt class="docutils literal"><span class="pre">.fred</span> <span class="pre">disable</span></tt> works if fred is a button (fred gets greyed out), but does not work if fred is a label (disabling of labels is not supported in Tk).</p> <p>The legal values of <em>someOptions</em> is action dependent. Some actions, like <tt class="docutils literal"><span class="pre">disable</span></tt>, require no arguments, others, like a text-entry box’s <tt class="docutils literal"><span class="pre">delete</span></tt> command, would need arguments to specify what range of text to delete.</p> </div> <div class="section" id="mapping-basic-tk-into-tkinter"> <span id="tkinter-basic-mapping"></span><h2>24.1.4. Mapping Basic Tk into Tkinter<a class="headerlink" href="#mapping-basic-tk-into-tkinter" title="Permalink to this headline">¶</a></h2> <p>Class commands in Tk correspond to class constructors in Tkinter.</p> <div class="highlight-python"><pre>button .fred =====> fred = Button()</pre> </div> <p>The master of an object is implicit in the new name given to it at creation time. In Tkinter, masters are specified explicitly.</p> <div class="highlight-python"><pre>button .panel.fred =====> fred = Button(panel)</pre> </div> <p>The configuration options in Tk are given in lists of hyphened tags followed by values. In Tkinter, options are specified as keyword-arguments in the instance constructor, and keyword-args for configure calls or as instance indices, in dictionary style, for established instances. See section <a class="reference internal" href="#tkinter-setting-options"><em>Setting Options</em></a> on setting options.</p> <div class="highlight-python"><pre>button .fred -fg red =====> fred = Button(panel, fg = "red") .fred configure -fg red =====> fred["fg"] = red OR ==> fred.config(fg = "red")</pre> </div> <p>In Tk, to perform an action on a widget, use the widget name as a command, and follow it with an action name, possibly with arguments (options). In Tkinter, you call methods on the class instance to invoke actions on the widget. The actions (methods) that a given widget can perform are listed in the Tkinter.py module.</p> <div class="highlight-python"><pre>.fred invoke =====> fred.invoke()</pre> </div> <p>To give a widget to the packer (geometry manager), you call pack with optional arguments. In Tkinter, the Pack class holds all this functionality, and the various forms of the pack command are implemented as methods. All widgets in <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> are subclassed from the Packer, and so inherit all the packing methods. See the <a class="reference internal" href="tix.html#module-Tix" title="Tix: Tk Extension Widgets for Tkinter"><tt class="xref py py-mod docutils literal"><span class="pre">Tix</span></tt></a> module documentation for additional information on the Form geometry manager.</p> <div class="highlight-python"><pre>pack .fred -side left =====> fred.pack(side = "left")</pre> </div> </div> <div class="section" id="how-tk-and-tkinter-are-related"> <h2>24.1.5. How Tk and Tkinter are Related<a class="headerlink" href="#how-tk-and-tkinter-are-related" title="Permalink to this headline">¶</a></h2> <p>From the top down:</p> <dl class="docutils"> <dt>Your App Here (Python)</dt> <dd>A Python application makes a <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> call.</dd> <dt>Tkinter (Python Module)</dt> <dd>This call (say, for example, creating a button widget), is implemented in the <em>Tkinter</em> module, which is written in Python. This Python function will parse the commands and the arguments and convert them into a form that makes them look as if they had come from a Tk script instead of a Python script.</dd> <dt>tkinter (C)</dt> <dd>These commands and their arguments will be passed to a C function in the <em>tkinter</em> - note the lowercase - extension module.</dd> <dt>Tk Widgets (C and Tcl)</dt> <dd>This C function is able to make calls into other C modules, including the C functions that make up the Tk library. Tk is implemented in C and some Tcl. The Tcl part of the Tk widgets is used to bind certain default behaviors to widgets, and is executed once at the point where the Python <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> module is imported. (The user never sees this stage).</dd> <dt>Tk (C)</dt> <dd>The Tk part of the Tk Widgets implement the final mapping to ...</dd> <dt>Xlib (C)</dt> <dd>the Xlib library to draw graphics on the screen.</dd> </dl> </div> <div class="section" id="handy-reference"> <h2>24.1.6. Handy Reference<a class="headerlink" href="#handy-reference" title="Permalink to this headline">¶</a></h2> <div class="section" id="setting-options"> <span id="tkinter-setting-options"></span><h3>24.1.6.1. Setting Options<a class="headerlink" href="#setting-options" title="Permalink to this headline">¶</a></h3> <p>Options control things like the color and border width of a widget. Options can be set in three ways:</p> <dl class="docutils"> <dt>At object creation time, using keyword arguments</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="n">fred</span> <span class="o">=</span> <span class="n">Button</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">fg</span> <span class="o">=</span> <span class="s">"red"</span><span class="p">,</span> <span class="n">bg</span> <span class="o">=</span> <span class="s">"blue"</span><span class="p">)</span> </pre></div> </div> </dd> <dt>After object creation, treating the option name like a dictionary index</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="n">fred</span><span class="p">[</span><span class="s">"fg"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"red"</span> <span class="n">fred</span><span class="p">[</span><span class="s">"bg"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"blue"</span> </pre></div> </div> </dd> <dt>Use the config() method to update multiple attrs subsequent to object creation</dt> <dd><div class="first last highlight-python"><div class="highlight"><pre><span class="n">fred</span><span class="o">.</span><span class="n">config</span><span class="p">(</span><span class="n">fg</span> <span class="o">=</span> <span class="s">"red"</span><span class="p">,</span> <span class="n">bg</span> <span class="o">=</span> <span class="s">"blue"</span><span class="p">)</span> </pre></div> </div> </dd> </dl> <p>For a complete explanation of a given option and its behavior, see the Tk man pages for the widget in question.</p> <p>Note that the man pages list “STANDARD OPTIONS” and “WIDGET SPECIFIC OPTIONS” for each widget. The former is a list of options that are common to many widgets, the latter are the options that are idiosyncratic to that particular widget. The Standard Options are documented on the <em class="manpage">options(3)</em> man page.</p> <p>No distinction between standard and widget-specific options is made in this document. Some options don’t apply to some kinds of widgets. Whether a given widget responds to a particular option depends on the class of the widget; buttons have a <tt class="docutils literal"><span class="pre">command</span></tt> option, labels do not.</p> <p>The options supported by a given widget are listed in that widget’s man page, or can be queried at runtime by calling the <tt class="xref py py-meth docutils literal"><span class="pre">config()</span></tt> method without arguments, or by calling the <tt class="xref py py-meth docutils literal"><span class="pre">keys()</span></tt> method on that widget. The return value of these calls is a dictionary whose key is the name of the option as a string (for example, <tt class="docutils literal"><span class="pre">'relief'</span></tt>) and whose values are 5-tuples.</p> <p>Some options, like <tt class="docutils literal"><span class="pre">bg</span></tt> are synonyms for common options with long names (<tt class="docutils literal"><span class="pre">bg</span></tt> is shorthand for “background”). Passing the <tt class="docutils literal"><span class="pre">config()</span></tt> method the name of a shorthand option will return a 2-tuple, not 5-tuple. The 2-tuple passed back will contain the name of the synonym and the “real” option (such as <tt class="docutils literal"><span class="pre">('bg',</span> <span class="pre">'background')</span></tt>).</p> <table border="1" class="docutils"> <colgroup> <col width="13%" /> <col width="61%" /> <col width="26%" /> </colgroup> <thead valign="bottom"> <tr class="row-odd"><th class="head">Index</th> <th class="head">Meaning</th> <th class="head">Example</th> </tr> </thead> <tbody valign="top"> <tr class="row-even"><td>0</td> <td>option name</td> <td><tt class="docutils literal"><span class="pre">'relief'</span></tt></td> </tr> <tr class="row-odd"><td>1</td> <td>option name for database lookup</td> <td><tt class="docutils literal"><span class="pre">'relief'</span></tt></td> </tr> <tr class="row-even"><td>2</td> <td>option class for database lookup</td> <td><tt class="docutils literal"><span class="pre">'Relief'</span></tt></td> </tr> <tr class="row-odd"><td>3</td> <td>default value</td> <td><tt class="docutils literal"><span class="pre">'raised'</span></tt></td> </tr> <tr class="row-even"><td>4</td> <td>current value</td> <td><tt class="docutils literal"><span class="pre">'groove'</span></tt></td> </tr> </tbody> </table> <p>Example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="k">print</span> <span class="n">fred</span><span class="o">.</span><span class="n">config</span><span class="p">()</span> <span class="go">{'relief' : ('relief', 'relief', 'Relief', 'raised', 'groove')}</span> </pre></div> </div> <p>Of course, the dictionary printed will include all the options available and their values. This is meant only as an example.</p> </div> <div class="section" id="the-packer"> <h3>24.1.6.2. The Packer<a class="headerlink" href="#the-packer" title="Permalink to this headline">¶</a></h3> <p id="index-0">The packer is one of Tk’s geometry-management mechanisms. Geometry managers are used to specify the relative positioning of the positioning of widgets within their container - their mutual <em>master</em>. In contrast to the more cumbersome <em>placer</em> (which is used less commonly, and we do not cover here), the packer takes qualitative relationship specification - <em>above</em>, <em>to the left of</em>, <em>filling</em>, etc - and works everything out to determine the exact placement coordinates for you.</p> <p>The size of any <em>master</em> widget is determined by the size of the “slave widgets” inside. The packer is used to control where slave widgets appear inside the master into which they are packed. You can pack widgets into frames, and frames into other frames, in order to achieve the kind of layout you desire. Additionally, the arrangement is dynamically adjusted to accommodate incremental changes to the configuration, once it is packed.</p> <p>Note that widgets do not appear until they have had their geometry specified with a geometry manager. It’s a common early mistake to leave out the geometry specification, and then be surprised when the widget is created but nothing appears. A widget will appear only after it has had, for example, the packer’s <tt class="xref py py-meth docutils literal"><span class="pre">pack()</span></tt> method applied to it.</p> <p>The pack() method can be called with keyword-option/value pairs that control where the widget is to appear within its container, and how it is to behave when the main application window is resized. Here are some examples:</p> <div class="highlight-python"><div class="highlight"><pre><span class="n">fred</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span> <span class="c"># defaults to side = "top"</span> <span class="n">fred</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">side</span> <span class="o">=</span> <span class="s">"left"</span><span class="p">)</span> <span class="n">fred</span><span class="o">.</span><span class="n">pack</span><span class="p">(</span><span class="n">expand</span> <span class="o">=</span> <span class="mi">1</span><span class="p">)</span> </pre></div> </div> </div> <div class="section" id="packer-options"> <h3>24.1.6.3. Packer Options<a class="headerlink" href="#packer-options" title="Permalink to this headline">¶</a></h3> <p>For more extensive information on the packer and the options that it can take, see the man pages and page 183 of John Ousterhout’s book.</p> <dl class="docutils"> <dt>anchor</dt> <dd>Anchor type. Denotes where the packer is to place each slave in its parcel.</dd> <dt>expand</dt> <dd>Boolean, <tt class="docutils literal"><span class="pre">0</span></tt> or <tt class="docutils literal"><span class="pre">1</span></tt>.</dd> <dt>fill</dt> <dd>Legal values: <tt class="docutils literal"><span class="pre">'x'</span></tt>, <tt class="docutils literal"><span class="pre">'y'</span></tt>, <tt class="docutils literal"><span class="pre">'both'</span></tt>, <tt class="docutils literal"><span class="pre">'none'</span></tt>.</dd> <dt>ipadx and ipady</dt> <dd>A distance - designating internal padding on each side of the slave widget.</dd> <dt>padx and pady</dt> <dd>A distance - designating external padding on each side of the slave widget.</dd> <dt>side</dt> <dd>Legal values are: <tt class="docutils literal"><span class="pre">'left'</span></tt>, <tt class="docutils literal"><span class="pre">'right'</span></tt>, <tt class="docutils literal"><span class="pre">'top'</span></tt>, <tt class="docutils literal"><span class="pre">'bottom'</span></tt>.</dd> </dl> </div> <div class="section" id="coupling-widget-variables"> <h3>24.1.6.4. Coupling Widget Variables<a class="headerlink" href="#coupling-widget-variables" title="Permalink to this headline">¶</a></h3> <p>The current-value setting of some widgets (like text entry widgets) can be connected directly to application variables by using special options. These options are <tt class="docutils literal"><span class="pre">variable</span></tt>, <tt class="docutils literal"><span class="pre">textvariable</span></tt>, <tt class="docutils literal"><span class="pre">onvalue</span></tt>, <tt class="docutils literal"><span class="pre">offvalue</span></tt>, and <tt class="docutils literal"><span class="pre">value</span></tt>. This connection works both ways: if the variable changes for any reason, the widget it’s connected to will be updated to reflect the new value.</p> <p>Unfortunately, in the current implementation of <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> it is not possible to hand over an arbitrary Python variable to a widget through a <tt class="docutils literal"><span class="pre">variable</span></tt> or <tt class="docutils literal"><span class="pre">textvariable</span></tt> option. The only kinds of variables for which this works are variables that are subclassed from a class called Variable, defined in the <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> module.</p> <p>There are many useful subclasses of Variable already defined: <tt class="xref py py-class docutils literal"><span class="pre">StringVar</span></tt>, <tt class="xref py py-class docutils literal"><span class="pre">IntVar</span></tt>, <tt class="xref py py-class docutils literal"><span class="pre">DoubleVar</span></tt>, and <tt class="xref py py-class docutils literal"><span class="pre">BooleanVar</span></tt>. To read the current value of such a variable, call the <tt class="xref py py-meth docutils literal"><span class="pre">get()</span></tt> method on it, and to change its value you call the <tt class="xref py py-meth docutils literal"><span class="pre">set()</span></tt> method. If you follow this protocol, the widget will always track the value of the variable, with no further intervention on your part.</p> <p>For example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">App</span><span class="p">(</span><span class="n">Frame</span><span class="p">):</span> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">master</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> <span class="n">Frame</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">master</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span> <span class="bp">self</span><span class="o">.</span><span class="n">entrythingy</span> <span class="o">=</span> <span class="n">Entry</span><span class="p">()</span> <span class="bp">self</span><span class="o">.</span><span class="n">entrythingy</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span> <span class="c"># here is the application variable</span> <span class="bp">self</span><span class="o">.</span><span class="n">contents</span> <span class="o">=</span> <span class="n">StringVar</span><span class="p">()</span> <span class="c"># set it to some value</span> <span class="bp">self</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="s">"this is a variable"</span><span class="p">)</span> <span class="c"># tell the entry widget to watch this variable</span> <span class="bp">self</span><span class="o">.</span><span class="n">entrythingy</span><span class="p">[</span><span class="s">"textvariable"</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">contents</span> <span class="c"># and here we get a callback when the user hits return.</span> <span class="c"># we will have the program print out the value of the</span> <span class="c"># application variable when the user hits return</span> <span class="bp">self</span><span class="o">.</span><span class="n">entrythingy</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">'<Key-Return>'</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">print_contents</span><span class="p">)</span> <span class="k">def</span> <span class="nf">print_contents</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span> <span class="k">print</span> <span class="s">"hi. contents of entry is now ---->"</span><span class="p">,</span> \ <span class="bp">self</span><span class="o">.</span><span class="n">contents</span><span class="o">.</span><span class="n">get</span><span class="p">()</span> </pre></div> </div> </div> <div class="section" id="the-window-manager"> <h3>24.1.6.5. The Window Manager<a class="headerlink" href="#the-window-manager" title="Permalink to this headline">¶</a></h3> <p id="index-1">In Tk, there is a utility command, <tt class="docutils literal"><span class="pre">wm</span></tt>, for interacting with the window manager. Options to the <tt class="docutils literal"><span class="pre">wm</span></tt> command allow you to control things like titles, placement, icon bitmaps, and the like. In <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a>, these commands have been implemented as methods on the <tt class="xref py py-class docutils literal"><span class="pre">Wm</span></tt> class. Toplevel widgets are subclassed from the <tt class="xref py py-class docutils literal"><span class="pre">Wm</span></tt> class, and so can call the <tt class="xref py py-class docutils literal"><span class="pre">Wm</span></tt> methods directly.</p> <p>To get at the toplevel window that contains a given widget, you can often just refer to the widget’s master. Of course if the widget has been packed inside of a frame, the master won’t represent a toplevel window. To get at the toplevel window that contains an arbitrary widget, you can call the <tt class="xref py py-meth docutils literal"><span class="pre">_root()</span></tt> method. This method begins with an underscore to denote the fact that this function is part of the implementation, and not an interface to Tk functionality.</p> <p>Here are some examples of typical usage:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">Tkinter</span> <span class="kn">import</span> <span class="o">*</span> <span class="k">class</span> <span class="nc">App</span><span class="p">(</span><span class="n">Frame</span><span class="p">):</span> <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">master</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> <span class="n">Frame</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">master</span><span class="p">)</span> <span class="bp">self</span><span class="o">.</span><span class="n">pack</span><span class="p">()</span> <span class="c"># create the application</span> <span class="n">myapp</span> <span class="o">=</span> <span class="n">App</span><span class="p">()</span> <span class="c">#</span> <span class="c"># here are method calls to the window manager class</span> <span class="c">#</span> <span class="n">myapp</span><span class="o">.</span><span class="n">master</span><span class="o">.</span><span class="n">title</span><span class="p">(</span><span class="s">"My Do-Nothing Application"</span><span class="p">)</span> <span class="n">myapp</span><span class="o">.</span><span class="n">master</span><span class="o">.</span><span class="n">maxsize</span><span class="p">(</span><span class="mi">1000</span><span class="p">,</span> <span class="mi">400</span><span class="p">)</span> <span class="c"># start the program</span> <span class="n">myapp</span><span class="o">.</span><span class="n">mainloop</span><span class="p">()</span> </pre></div> </div> </div> <div class="section" id="tk-option-data-types"> <h3>24.1.6.6. Tk Option Data Types<a class="headerlink" href="#tk-option-data-types" title="Permalink to this headline">¶</a></h3> <dl class="docutils" id="index-2"> <dt>anchor</dt> <dd>Legal values are points of the compass: <tt class="docutils literal"><span class="pre">"n"</span></tt>, <tt class="docutils literal"><span class="pre">"ne"</span></tt>, <tt class="docutils literal"><span class="pre">"e"</span></tt>, <tt class="docutils literal"><span class="pre">"se"</span></tt>, <tt class="docutils literal"><span class="pre">"s"</span></tt>, <tt class="docutils literal"><span class="pre">"sw"</span></tt>, <tt class="docutils literal"><span class="pre">"w"</span></tt>, <tt class="docutils literal"><span class="pre">"nw"</span></tt>, and also <tt class="docutils literal"><span class="pre">"center"</span></tt>.</dd> <dt>bitmap</dt> <dd>There are eight built-in, named bitmaps: <tt class="docutils literal"><span class="pre">'error'</span></tt>, <tt class="docutils literal"><span class="pre">'gray25'</span></tt>, <tt class="docutils literal"><span class="pre">'gray50'</span></tt>, <tt class="docutils literal"><span class="pre">'hourglass'</span></tt>, <tt class="docutils literal"><span class="pre">'info'</span></tt>, <tt class="docutils literal"><span class="pre">'questhead'</span></tt>, <tt class="docutils literal"><span class="pre">'question'</span></tt>, <tt class="docutils literal"><span class="pre">'warning'</span></tt>. To specify an X bitmap filename, give the full path to the file, preceded with an <tt class="docutils literal"><span class="pre">@</span></tt>, as in <tt class="docutils literal"><span class="pre">"@/usr/contrib/bitmap/gumby.bit"</span></tt>.</dd> <dt>boolean</dt> <dd>You can pass integers 0 or 1 or the strings <tt class="docutils literal"><span class="pre">"yes"</span></tt> or <tt class="docutils literal"><span class="pre">"no"</span></tt> .</dd> <dt>callback</dt> <dd><p class="first">This is any Python function that takes no arguments. For example:</p> <div class="last highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">print_it</span><span class="p">():</span> <span class="k">print</span> <span class="s">"hi there"</span> <span class="n">fred</span><span class="p">[</span><span class="s">"command"</span><span class="p">]</span> <span class="o">=</span> <span class="n">print_it</span> </pre></div> </div> </dd> <dt>color</dt> <dd>Colors can be given as the names of X colors in the rgb.txt file, or as strings representing RGB values in 4 bit: <tt class="docutils literal"><span class="pre">"#RGB"</span></tt>, 8 bit: <tt class="docutils literal"><span class="pre">"#RRGGBB"</span></tt>, 12 bit” <tt class="docutils literal"><span class="pre">"#RRRGGGBBB"</span></tt>, or 16 bit <tt class="docutils literal"><span class="pre">"#RRRRGGGGBBBB"</span></tt> ranges, where R,G,B here represent any legal hex digit. See page 160 of Ousterhout’s book for details.</dd> <dt>cursor</dt> <dd>The standard X cursor names from <tt class="file docutils literal"><span class="pre">cursorfont.h</span></tt> can be used, without the <tt class="docutils literal"><span class="pre">XC_</span></tt> prefix. For example to get a hand cursor (<tt class="xref py py-const docutils literal"><span class="pre">XC_hand2</span></tt>), use the string <tt class="docutils literal"><span class="pre">"hand2"</span></tt>. You can also specify a bitmap and mask file of your own. See page 179 of Ousterhout’s book.</dd> <dt>distance</dt> <dd>Screen distances can be specified in either pixels or absolute distances. Pixels are given as numbers and absolute distances as strings, with the trailing character denoting units: <tt class="docutils literal"><span class="pre">c</span></tt> for centimetres, <tt class="docutils literal"><span class="pre">i</span></tt> for inches, <tt class="docutils literal"><span class="pre">m</span></tt> for millimetres, <tt class="docutils literal"><span class="pre">p</span></tt> for printer’s points. For example, 3.5 inches is expressed as <tt class="docutils literal"><span class="pre">"3.5i"</span></tt>.</dd> <dt>font</dt> <dd>Tk uses a list font name format, such as <tt class="docutils literal"><span class="pre">{courier</span> <span class="pre">10</span> <span class="pre">bold}</span></tt>. Font sizes with positive numbers are measured in points; sizes with negative numbers are measured in pixels.</dd> <dt>geometry</dt> <dd>This is a string of the form <tt class="docutils literal"><span class="pre">widthxheight</span></tt>, where width and height are measured in pixels for most widgets (in characters for widgets displaying text). For example: <tt class="docutils literal"><span class="pre">fred["geometry"]</span> <span class="pre">=</span> <span class="pre">"200x100"</span></tt>.</dd> <dt>justify</dt> <dd>Legal values are the strings: <tt class="docutils literal"><span class="pre">"left"</span></tt>, <tt class="docutils literal"><span class="pre">"center"</span></tt>, <tt class="docutils literal"><span class="pre">"right"</span></tt>, and <tt class="docutils literal"><span class="pre">"fill"</span></tt>.</dd> <dt>region</dt> <dd>This is a string with four space-delimited elements, each of which is a legal distance (see above). For example: <tt class="docutils literal"><span class="pre">"2</span> <span class="pre">3</span> <span class="pre">4</span> <span class="pre">5"</span></tt> and <tt class="docutils literal"><span class="pre">"3i</span> <span class="pre">2i</span> <span class="pre">4.5i</span> <span class="pre">2i"</span></tt> and <tt class="docutils literal"><span class="pre">"3c</span> <span class="pre">2c</span> <span class="pre">4c</span> <span class="pre">10.43c"</span></tt> are all legal regions.</dd> <dt>relief</dt> <dd>Determines what the border style of a widget will be. Legal values are: <tt class="docutils literal"><span class="pre">"raised"</span></tt>, <tt class="docutils literal"><span class="pre">"sunken"</span></tt>, <tt class="docutils literal"><span class="pre">"flat"</span></tt>, <tt class="docutils literal"><span class="pre">"groove"</span></tt>, and <tt class="docutils literal"><span class="pre">"ridge"</span></tt>.</dd> <dt>scrollcommand</dt> <dd>This is almost always the <tt class="xref py py-meth docutils literal"><span class="pre">set()</span></tt> method of some scrollbar widget, but can be any widget method that takes a single argument. Refer to the file <tt class="file docutils literal"><span class="pre">Demo/tkinter/matt/canvas-with-scrollbars.py</span></tt> in the Python source distribution for an example.</dd> <dt>wrap:</dt> <dd>Must be one of: <tt class="docutils literal"><span class="pre">"none"</span></tt>, <tt class="docutils literal"><span class="pre">"char"</span></tt>, or <tt class="docutils literal"><span class="pre">"word"</span></tt>.</dd> </dl> </div> <div class="section" id="bindings-and-events"> <h3>24.1.6.7. Bindings and Events<a class="headerlink" href="#bindings-and-events" title="Permalink to this headline">¶</a></h3> <p id="index-3">The bind method from the widget command allows you to watch for certain events and to have a callback function trigger when that event type occurs. The form of the bind method is:</p> <div class="highlight-python"><pre>def bind(self, sequence, func, add=''):</pre> </div> <p>where:</p> <dl class="docutils"> <dt>sequence</dt> <dd>is a string that denotes the target kind of event. (See the bind man page and page 201 of John Ousterhout’s book for details).</dd> <dt>func</dt> <dd>is a Python function, taking one argument, to be invoked when the event occurs. An Event instance will be passed as the argument. (Functions deployed this way are commonly known as <em>callbacks</em>.)</dd> <dt>add</dt> <dd>is optional, either <tt class="docutils literal"><span class="pre">''</span></tt> or <tt class="docutils literal"><span class="pre">'+'</span></tt>. Passing an empty string denotes that this binding is to replace any other bindings that this event is associated with. Passing a <tt class="docutils literal"><span class="pre">'+'</span></tt> means that this function is to be added to the list of functions bound to this event type.</dd> </dl> <p>For example:</p> <div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">turnRed</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">event</span><span class="p">):</span> <span class="n">event</span><span class="o">.</span><span class="n">widget</span><span class="p">[</span><span class="s">"activeforeground"</span><span class="p">]</span> <span class="o">=</span> <span class="s">"red"</span> <span class="bp">self</span><span class="o">.</span><span class="n">button</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="s">"<Enter>"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">turnRed</span><span class="p">)</span> </pre></div> </div> <p>Notice how the widget field of the event is being accessed in the <tt class="xref py py-meth docutils literal"><span class="pre">turnRed()</span></tt> callback. This field contains the widget that caught the X event. The following table lists the other event fields you can access, and how they are denoted in Tk, which can be useful when referring to the Tk man pages.</p> <div class="highlight-python"><pre>Tk Tkinter Event Field Tk Tkinter Event Field -- ------------------- -- ------------------- %f focus %A char %h height %E send_event %k keycode %K keysym %s state %N keysym_num %t time %T type %w width %W widget %x x %X x_root %y y %Y y_root</pre> </div> </div> <div class="section" id="the-index-parameter"> <h3>24.1.6.8. The index Parameter<a class="headerlink" href="#the-index-parameter" title="Permalink to this headline">¶</a></h3> <p>A number of widgets require”index” parameters to be passed. These are used to point at a specific place in a Text widget, or to particular characters in an Entry widget, or to particular menu items in a Menu widget.</p> <dl class="docutils"> <dt>Entry widget indexes (index, view index, etc.)</dt> <dd><p class="first">Entry widgets have options that refer to character positions in the text being displayed. You can use these <a class="reference internal" href="#module-Tkinter" title="Tkinter: Interface to Tcl/Tk for graphical user interfaces"><tt class="xref py py-mod docutils literal"><span class="pre">Tkinter</span></tt></a> functions to access these special points in text widgets:</p> <dl class="last docutils"> <dt>AtEnd()</dt> <dd>refers to the last position in the text</dd> <dt>AtInsert()</dt> <dd>refers to the point where the text cursor is</dd> <dt>AtSelFirst()</dt> <dd>indicates the beginning point of the selected text</dd> <dt>AtSelLast()</dt> <dd>denotes the last point of the selected text and finally</dd> <dt>At(x[, y])</dt> <dd>refers to the character at pixel location <em>x</em>, <em>y</em> (with <em>y</em> not used in the case of a text entry widget, which contains a single line of text).</dd> </dl> </dd> <dt>Text widget indexes</dt> <dd>The index notation for Text widgets is very rich and is best described in the Tk man pages.</dd> <dt>Menu indexes (menu.invoke(), menu.entryconfig(), etc.)</dt> <dd><p class="first">Some options and methods for menus manipulate specific menu entries. Anytime a menu index is needed for an option or a parameter, you may pass in:</p> <ul class="last simple"> <li>an integer which refers to the numeric position of the entry in the widget, counted from the top, starting with 0;</li> <li>the string <tt class="docutils literal"><span class="pre">'active'</span></tt>, which refers to the menu position that is currently under the cursor;</li> <li>the string <tt class="docutils literal"><span class="pre">"last"</span></tt> which refers to the last menu item;</li> <li>An integer preceded by <tt class="docutils literal"><span class="pre">@</span></tt>, as in <tt class="docutils literal"><span class="pre">@6</span></tt>, where the integer is interpreted as a y pixel coordinate in the menu’s coordinate system;</li> <li>the string <tt class="docutils literal"><span class="pre">"none"</span></tt>, which indicates no menu entry at all, most often used with menu.activate() to deactivate all entries, and finally,</li> <li>a text string that is pattern matched against the label of the menu entry, as scanned from the top of the menu to the bottom. Note that this index type is considered after all the others, which means that matches for menu items labelled <tt class="docutils literal"><span class="pre">last</span></tt>, <tt class="docutils literal"><span class="pre">active</span></tt>, or <tt class="docutils literal"><span class="pre">none</span></tt> may be interpreted as the above literals, instead.</li> </ul> </dd> </dl> </div> <div class="section" id="images"> <h3>24.1.6.9. Images<a class="headerlink" href="#images" title="Permalink to this headline">¶</a></h3> <p>Bitmap/Pixelmap images can be created through the subclasses of <tt class="xref py py-class docutils literal"><span class="pre">Tkinter.Image</span></tt>:</p> <ul class="simple"> <li><tt class="xref py py-class docutils literal"><span class="pre">BitmapImage</span></tt> can be used for X11 bitmap data.</li> <li><tt class="xref py py-class docutils literal"><span class="pre">PhotoImage</span></tt> can be used for GIF and PPM/PGM color bitmaps.</li> </ul> <p>Either type of image is created through either the <tt class="docutils literal"><span class="pre">file</span></tt> or the <tt class="docutils literal"><span class="pre">data</span></tt> option (other options are available as well).</p> <p>The image object can then be used wherever an <tt class="docutils literal"><span class="pre">image</span></tt> option is supported by some widget (e.g. labels, buttons, menus). In these cases, Tk will not keep a reference to the image. When the last Python reference to the image object is deleted, the image data is deleted as well, and Tk will display an empty box wherever the image was used.</p> </div> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">24.1. <tt class="docutils literal"><span class="pre">Tkinter</span></tt> — Python interface to Tcl/Tk</a><ul> <li><a class="reference internal" href="#tkinter-modules">24.1.1. Tkinter Modules</a></li> <li><a class="reference internal" href="#tkinter-life-preserver">24.1.2. Tkinter Life Preserver</a><ul> <li><a class="reference internal" href="#how-to-use-this-section">24.1.2.1. How To Use This Section</a></li> <li><a class="reference internal" href="#a-simple-hello-world-program">24.1.2.2. A Simple Hello World Program</a></li> </ul> </li> <li><a class="reference internal" href="#a-very-quick-look-at-tcl-tk">24.1.3. A (Very) Quick Look at Tcl/Tk</a></li> <li><a class="reference internal" href="#mapping-basic-tk-into-tkinter">24.1.4. Mapping Basic Tk into Tkinter</a></li> <li><a class="reference internal" href="#how-tk-and-tkinter-are-related">24.1.5. How Tk and Tkinter are Related</a></li> <li><a class="reference internal" href="#handy-reference">24.1.6. Handy Reference</a><ul> <li><a class="reference internal" href="#setting-options">24.1.6.1. Setting Options</a></li> <li><a class="reference internal" href="#the-packer">24.1.6.2. The Packer</a></li> <li><a class="reference internal" href="#packer-options">24.1.6.3. Packer Options</a></li> <li><a class="reference internal" href="#coupling-widget-variables">24.1.6.4. Coupling Widget Variables</a></li> <li><a class="reference internal" href="#the-window-manager">24.1.6.5. The Window Manager</a></li> <li><a class="reference internal" href="#tk-option-data-types">24.1.6.6. Tk Option Data Types</a></li> <li><a class="reference internal" href="#bindings-and-events">24.1.6.7. Bindings and Events</a></li> <li><a class="reference internal" href="#the-index-parameter">24.1.6.8. The index Parameter</a></li> <li><a class="reference internal" href="#images">24.1.6.9. Images</a></li> </ul> </li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="tk.html" title="previous chapter">24. Graphical User Interfaces with Tk</a></p> <h4>Next topic</h4> <p class="topless"><a href="ttk.html" title="next chapter">24.2. <tt class="docutils literal"><span class="pre">ttk</span></tt> — Tk themed widgets</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li><a href="../_sources/library/tkinter.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="ttk.html" title="24.2. ttk — Tk themed widgets" >next</a> |</li> <li class="right" > <a href="tk.html" title="24. Graphical User Interfaces with Tk" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="http://www.python.org/">Python</a> »</li> <li> <a href="../index.html">Python 2.7.5 documentation</a> » </li> <li><a href="index.html" >The Python Standard Library</a> »</li> <li><a href="tk.html" >24. Graphical User Interfaces with Tk</a> »</li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 1990-2019, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="http://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Jul 03, 2019. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.1.3. </div> </body> </html>
Close