summaryrefslogtreecommitdiffstats
path: root/Lib/tkinter
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/tkinter')
-rw-r--r--Lib/tkinter/__init__.py220
-rw-r--r--Lib/tkinter/__main__.py7
-rw-r--r--Lib/tkinter/font.py2
-rw-r--r--Lib/tkinter/scrolledtext.py7
-rw-r--r--Lib/tkinter/simpledialog.py2
-rw-r--r--Lib/tkinter/test/support.py46
-rw-r--r--Lib/tkinter/test/test_tkinter/test_font.py33
-rw-r--r--Lib/tkinter/test/test_tkinter/test_loadtk.py3
-rw-r--r--Lib/tkinter/test/test_tkinter/test_misc.py45
-rw-r--r--Lib/tkinter/test/test_ttk/test_functions.py40
-rw-r--r--Lib/tkinter/test/test_ttk/test_widgets.py32
-rw-r--r--Lib/tkinter/tix.py183
-rw-r--r--Lib/tkinter/ttk.py138
13 files changed, 499 insertions, 259 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index c5f3c1b..1286779 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -39,6 +39,7 @@ if sys.platform == "win32":
import _tkinter # If this fails your Python may not be configured for Tk
TclError = _tkinter.TclError
from tkinter.constants import *
+import re
wantobjects = 1
@@ -50,6 +51,34 @@ WRITABLE = _tkinter.WRITABLE
EXCEPTION = _tkinter.EXCEPTION
+_magic_re = re.compile(r'([\\{}])')
+_space_re = re.compile(r'([\s])', re.ASCII)
+
+def _join(value):
+ """Internal function."""
+ return ' '.join(map(_stringify, value))
+
+def _stringify(value):
+ """Internal function."""
+ if isinstance(value, (list, tuple)):
+ if len(value) == 1:
+ value = _stringify(value[0])
+ if value[0] == '{':
+ value = '{%s}' % value
+ else:
+ value = '{%s}' % _join(value)
+ else:
+ value = str(value)
+ if not value:
+ value = '{}'
+ elif _magic_re.search(value):
+ # add '\' before special characters and spaces
+ value = _magic_re.sub(r'\\\1', value)
+ value = _space_re.sub(r'\\\1', value)
+ elif value[0] == '"' or _space_re.search(value):
+ value = '{%s}' % value
+ return value
+
def _flatten(seq):
"""Internal function."""
res = ()
@@ -146,8 +175,12 @@ def _tkerror(err):
"""Internal function."""
pass
-def _exit(code='0'):
- """Internal function. Calling it will throw the exception SystemExit."""
+def _exit(code=0):
+ """Internal function. Calling it will raise the exception SystemExit."""
+ try:
+ code = int(code)
+ except ValueError:
+ pass
raise SystemExit(code)
_varnum = 0
@@ -376,7 +409,7 @@ class Misc:
background, highlightColor, selectForeground,
disabledForeground, insertBackground, troughColor."""
self.tk.call(('tk_setPalette',)
- + _flatten(args) + _flatten(kw.items()))
+ + _flatten(args) + _flatten(list(kw.items())))
def tk_menuBar(self, *args):
"""Do not use. Needed in Tk 3.6 and earlier."""
pass # obsolete since Tk 4.0
@@ -526,12 +559,19 @@ class Misc:
The type keyword specifies the form in which the data is
to be returned and should be an atom name such as STRING
- or FILE_NAME. Type defaults to STRING.
+ or FILE_NAME. Type defaults to STRING, except on X11, where the default
+ is to try UTF8_STRING and fall back to STRING.
This command is equivalent to:
selection_get(CLIPBOARD)
"""
+ if 'type' not in kw and self._windowingsystem == 'x11':
+ try:
+ kw['type'] = 'UTF8_STRING'
+ return self.tk.call(('clipboard', 'get') + self._options(kw))
+ except TclError:
+ del kw['type']
return self.tk.call(('clipboard', 'get') + self._options(kw))
def clipboard_clear(self, **kw):
@@ -613,8 +653,16 @@ class Misc:
A keyword parameter selection specifies the name of
the selection and defaults to PRIMARY. A keyword
parameter displayof specifies a widget on the display
- to use."""
+ to use. A keyword parameter type specifies the form of data to be
+ fetched, defaulting to STRING except on X11, where UTF8_STRING is tried
+ before STRING."""
if 'displayof' not in kw: kw['displayof'] = self._w
+ if 'type' not in kw and self._windowingsystem == 'x11':
+ try:
+ kw['type'] = 'UTF8_STRING'
+ return self.tk.call(('selection', 'get') + self._options(kw))
+ except TclError:
+ del kw['type']
return self.tk.call(('selection', 'get') + self._options(kw))
def selection_handle(self, command, **kw):
"""Specify a function COMMAND to call if the X
@@ -1029,6 +1077,15 @@ class Misc:
if displayof is None:
return ('-displayof', self._w)
return ()
+ @property
+ def _windowingsystem(self):
+ """Internal function."""
+ try:
+ return self._root()._windowingsystem_cached
+ except AttributeError:
+ ws = self._root()._windowingsystem_cached = \
+ self.tk.call('tk', 'windowingsystem')
+ return ws
def _options(self, cnf, kw = None):
"""Internal function."""
if kw:
@@ -1039,7 +1096,7 @@ class Misc:
for k, v in cnf.items():
if v is not None:
if k[-1] == '_': k = k[:-1]
- if hasattr(v, '__call__'):
+ if callable(v):
v = self._register(v)
elif isinstance(v, (tuple, list)):
nv = []
@@ -1047,7 +1104,7 @@ class Misc:
if isinstance(item, int):
nv.append(str(item))
elif isinstance(item, str):
- nv.append(('{%s}' if ' ' in item else '%s') % item)
+ nv.append(_stringify(item))
else:
break
else:
@@ -1397,12 +1454,54 @@ class CallWrapper:
if self.subst:
args = self.subst(*args)
return self.func(*args)
- except SystemExit as msg:
- raise SystemExit(msg)
+ except SystemExit:
+ raise
except:
self.widget._report_exception()
+class XView:
+ """Mix-in class for querying and changing the horizontal position
+ of a widget's window."""
+
+ def xview(self, *args):
+ """Query and change the horizontal position of the view."""
+ res = self.tk.call(self._w, 'xview', *args)
+ if not args:
+ return self._getdoubles(res)
+
+ def xview_moveto(self, fraction):
+ """Adjusts the view in the window so that FRACTION of the
+ total width of the canvas is off-screen to the left."""
+ self.tk.call(self._w, 'xview', 'moveto', fraction)
+
+ def xview_scroll(self, number, what):
+ """Shift the x-view according to NUMBER which is measured in "units"
+ or "pages" (WHAT)."""
+ self.tk.call(self._w, 'xview', 'scroll', number, what)
+
+
+class YView:
+ """Mix-in class for querying and changing the vertical position
+ of a widget's window."""
+
+ def yview(self, *args):
+ """Query and change the vertical position of the view."""
+ res = self.tk.call(self._w, 'yview', *args)
+ if not args:
+ return self._getdoubles(res)
+
+ def yview_moveto(self, fraction):
+ """Adjusts the view in the window so that FRACTION of the
+ total height of the canvas is off-screen to the top."""
+ self.tk.call(self._w, 'yview', 'moveto', fraction)
+
+ def yview_scroll(self, number, what):
+ """Shift the y-view according to NUMBER which is measured in
+ "units" or "pages" (WHAT)."""
+ self.tk.call(self._w, 'yview', 'scroll', number, what)
+
+
class Wm:
"""Provides functions for the communication with the window manager."""
@@ -1566,7 +1665,7 @@ class Wm:
"""Bind function FUNC to command NAME for this widget.
Return the function bound to NAME if None is given. NAME could be
e.g. "WM_SAVE_YOURSELF" or "WM_DELETE_WINDOW"."""
- if hasattr(func, '__call__'):
+ if callable(func):
command = self._register(func)
else:
command = func
@@ -2043,7 +2142,7 @@ def At(x, y=None):
else:
return '@%r,%r' % (x, y)
-class Canvas(Widget):
+class Canvas(Widget, XView, YView):
"""Canvas widget to display graphical elements like lines or text."""
def __init__(self, master=None, cnf={}, **kw):
"""Construct a canvas widget with the parent MASTER.
@@ -2283,30 +2382,6 @@ class Canvas(Widget):
def type(self, tagOrId):
"""Return the type of the item TAGORID."""
return self.tk.call(self._w, 'type', tagOrId) or None
- def xview(self, *args):
- """Query and change horizontal position of the view."""
- if not args:
- return self._getdoubles(self.tk.call(self._w, 'xview'))
- self.tk.call((self._w, 'xview') + args)
- def xview_moveto(self, fraction):
- """Adjusts the view in the window so that FRACTION of the
- total width of the canvas is off-screen to the left."""
- self.tk.call(self._w, 'xview', 'moveto', fraction)
- def xview_scroll(self, number, what):
- """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
- self.tk.call(self._w, 'xview', 'scroll', number, what)
- def yview(self, *args):
- """Query and change vertical position of the view."""
- if not args:
- return self._getdoubles(self.tk.call(self._w, 'yview'))
- self.tk.call((self._w, 'yview') + args)
- def yview_moveto(self, fraction):
- """Adjusts the view in the window so that FRACTION of the
- total height of the canvas is off-screen to the top."""
- self.tk.call(self._w, 'yview', 'moveto', fraction)
- def yview_scroll(self, number, what):
- """Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
- self.tk.call(self._w, 'yview', 'scroll', number, what)
class Checkbutton(Widget):
"""Checkbutton widget which is either in on- or off-state."""
@@ -2337,7 +2412,7 @@ class Checkbutton(Widget):
"""Toggle the button."""
self.tk.call(self._w, 'toggle')
-class Entry(Widget):
+class Entry(Widget, XView):
"""Entry widget which allows to display simple text."""
def __init__(self, master=None, cnf={}, **kw):
"""Construct an entry widget with the parent MASTER.
@@ -2388,7 +2463,8 @@ class Entry(Widget):
self.tk.call(self._w, 'selection', 'from', index)
select_from = selection_from
def selection_present(self):
- """Return whether the widget has the selection."""
+ """Return True if there are characters selected in the entry, False
+ otherwise."""
return self.tk.getboolean(
self.tk.call(self._w, 'selection', 'present'))
select_present = selection_present
@@ -2400,16 +2476,6 @@ class Entry(Widget):
"""Set the variable end of a selection to INDEX."""
self.tk.call(self._w, 'selection', 'to', index)
select_to = selection_to
- def xview(self, index):
- """Query and change horizontal position of the view."""
- self.tk.call(self._w, 'xview', index)
- def xview_moveto(self, fraction):
- """Adjust the view in the window so that FRACTION of the
- total width of the entry is off-screen to the left."""
- self.tk.call(self._w, 'xview', 'moveto', fraction)
- def xview_scroll(self, number, what):
- """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
- self.tk.call(self._w, 'xview', 'scroll', number, what)
class Frame(Widget):
"""Frame widget which may contain other widgets and can have a 3D border."""
@@ -2451,7 +2517,7 @@ class Label(Widget):
"""
Widget.__init__(self, master, 'label', cnf, kw)
-class Listbox(Widget):
+class Listbox(Widget, XView, YView):
"""Listbox widget which can display a list of strings."""
def __init__(self, master=None, cnf={}, **kw):
"""Construct a listbox widget with the parent MASTER.
@@ -2530,30 +2596,6 @@ class Listbox(Widget):
def size(self):
"""Return the number of elements in the listbox."""
return getint(self.tk.call(self._w, 'size'))
- def xview(self, *what):
- """Query and change horizontal position of the view."""
- if not what:
- return self._getdoubles(self.tk.call(self._w, 'xview'))
- self.tk.call((self._w, 'xview') + what)
- def xview_moveto(self, fraction):
- """Adjust the view in the window so that FRACTION of the
- total width of the entry is off-screen to the left."""
- self.tk.call(self._w, 'xview', 'moveto', fraction)
- def xview_scroll(self, number, what):
- """Shift the x-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
- self.tk.call(self._w, 'xview', 'scroll', number, what)
- def yview(self, *what):
- """Query and change vertical position of the view."""
- if not what:
- return self._getdoubles(self.tk.call(self._w, 'yview'))
- self.tk.call((self._w, 'yview') + what)
- def yview_moveto(self, fraction):
- """Adjust the view in the window so that FRACTION of the
- total width of the entry is off-screen to the top."""
- self.tk.call(self._w, 'yview', 'moveto', fraction)
- def yview_scroll(self, number, what):
- """Shift the y-view according to NUMBER which is measured in "units" or "pages" (WHAT)."""
- self.tk.call(self._w, 'yview', 'scroll', number, what)
def itemcget(self, index, option):
"""Return the resource value for an ITEM and an OPTION."""
return self.tk.call(
@@ -2800,7 +2842,7 @@ class Scrollbar(Widget):
-class Text(Widget):
+class Text(Widget, XView, YView):
"""Text widget which can display text in various forms."""
def __init__(self, master=None, cnf={}, **kw):
"""Construct a text widget with the parent MASTER.
@@ -3122,32 +3164,6 @@ class Text(Widget):
"""Return all names of embedded windows in this widget."""
return self.tk.splitlist(
self.tk.call(self._w, 'window', 'names'))
- def xview(self, *what):
- """Query and change horizontal position of the view."""
- if not what:
- return self._getdoubles(self.tk.call(self._w, 'xview'))
- self.tk.call((self._w, 'xview') + what)
- def xview_moveto(self, fraction):
- """Adjusts the view in the window so that FRACTION of the
- total width of the canvas is off-screen to the left."""
- self.tk.call(self._w, 'xview', 'moveto', fraction)
- def xview_scroll(self, number, what):
- """Shift the x-view according to NUMBER which is measured
- in "units" or "pages" (WHAT)."""
- self.tk.call(self._w, 'xview', 'scroll', number, what)
- def yview(self, *what):
- """Query and change vertical position of the view."""
- if not what:
- return self._getdoubles(self.tk.call(self._w, 'yview'))
- self.tk.call((self._w, 'yview') + what)
- def yview_moveto(self, fraction):
- """Adjusts the view in the window so that FRACTION of the
- total height of the canvas is off-screen to the top."""
- self.tk.call(self._w, 'yview', 'moveto', fraction)
- def yview_scroll(self, number, what):
- """Shift the y-view according to NUMBER which is measured
- in "units" or "pages" (WHAT)."""
- self.tk.call(self._w, 'yview', 'scroll', number, what)
def yview_pickplace(self, *what):
"""Obsolete function, use see."""
self.tk.call((self._w, 'yview', '-pickplace') + what)
@@ -3221,7 +3237,7 @@ class Image:
elif kw: cnf = kw
options = ()
for k, v in cnf.items():
- if hasattr(v, '__call__'):
+ if callable(v):
v = self._register(v)
options = options + ('-'+k, v)
self.tk.call(('image', 'create', imgtype, name,) + options)
@@ -3244,7 +3260,7 @@ class Image:
for k, v in _cnfmerge(kw).items():
if v is not None:
if k[-1] == '_': k = k[:-1]
- if hasattr(v, '__call__'):
+ if callable(v):
v = self._register(v)
res = res + ('-'+k, v)
self.tk.call((self.name, 'config') + res)
@@ -3333,7 +3349,7 @@ def image_names(): return _default_root.tk.call('image', 'names')
def image_types(): return _default_root.tk.call('image', 'types')
-class Spinbox(Widget):
+class Spinbox(Widget, XView):
"""spinbox widget."""
def __init__(self, master=None, cnf={}, **kw):
"""Construct a spinbox widget with the parent MASTER.
diff --git a/Lib/tkinter/__main__.py b/Lib/tkinter/__main__.py
new file mode 100644
index 0000000..757880d
--- /dev/null
+++ b/Lib/tkinter/__main__.py
@@ -0,0 +1,7 @@
+"""Main entry point"""
+
+import sys
+if sys.argv[0].endswith("__main__.py"):
+ sys.argv[0] = "python -m tkinter"
+from . import _test as main
+main()
diff --git a/Lib/tkinter/font.py b/Lib/tkinter/font.py
index 1ec760e..5425b06 100644
--- a/Lib/tkinter/font.py
+++ b/Lib/tkinter/font.py
@@ -97,7 +97,7 @@ class Font:
return self.name
def __eq__(self, other):
- return self.name == other.name and isinstance(other, Font)
+ return isinstance(other, Font) and self.name == other.name
def __getitem__(self, key):
return self.cget(key)
diff --git a/Lib/tkinter/scrolledtext.py b/Lib/tkinter/scrolledtext.py
index d9af67c..9aa936a 100644
--- a/Lib/tkinter/scrolledtext.py
+++ b/Lib/tkinter/scrolledtext.py
@@ -27,8 +27,11 @@ class ScrolledText(Text):
self.pack(side=LEFT, fill=BOTH, expand=True)
self.vbar['command'] = self.yview
- # Copy geometry methods of self.frame -- hack!
- methods = vars(Pack).keys() + vars(Grid).keys() + vars(Place).keys()
+ # Copy geometry methods of self.frame without overriding Text
+ # methods -- hack!
+ text_meths = vars(Text).keys()
+ methods = vars(Pack).keys() | vars(Grid).keys() | vars(Place).keys()
+ methods = methods.difference(text_meths)
for m in methods:
if m[0] != '_' and m != 'config' and m != 'configure':
diff --git a/Lib/tkinter/simpledialog.py b/Lib/tkinter/simpledialog.py
index 885804b..45302b4 100644
--- a/Lib/tkinter/simpledialog.py
+++ b/Lib/tkinter/simpledialog.py
@@ -282,7 +282,7 @@ class _QueryDialog(Dialog):
self.entry = Entry(master, name="entry")
self.entry.grid(row=1, padx=5, sticky=W+E)
- if self.initialvalue:
+ if self.initialvalue is not None:
self.entry.insert(0, self.initialvalue)
self.entry.select_range(0, END)
diff --git a/Lib/tkinter/test/support.py b/Lib/tkinter/test/support.py
index 97212fb..6dd6d4a 100644
--- a/Lib/tkinter/test/support.py
+++ b/Lib/tkinter/test/support.py
@@ -1,6 +1,52 @@
+import sys
import tkinter
+import unittest
+
+_tk_unavailable = None
+
+def check_tk_availability():
+ """Check that Tk is installed and available."""
+ global _tk_unavailable
+
+ if _tk_unavailable is None:
+ _tk_unavailable = False
+ if sys.platform == 'darwin':
+ # The Aqua Tk implementations on OS X can abort the process if
+ # being called in an environment where a window server connection
+ # cannot be made, for instance when invoked by a buildbot or ssh
+ # process not running under the same user id as the current console
+ # user. To avoid that, raise an exception if the window manager
+ # connection is not available.
+ from ctypes import cdll, c_int, pointer, Structure
+ from ctypes.util import find_library
+
+ app_services = cdll.LoadLibrary(find_library("ApplicationServices"))
+
+ if app_services.CGMainDisplayID() == 0:
+ _tk_unavailable = "cannot run without OS X window manager"
+ else:
+ class ProcessSerialNumber(Structure):
+ _fields_ = [("highLongOfPSN", c_int),
+ ("lowLongOfPSN", c_int)]
+ psn = ProcessSerialNumber()
+ psn_p = pointer(psn)
+ if ( (app_services.GetCurrentProcess(psn_p) < 0) or
+ (app_services.SetFrontProcess(psn_p) < 0) ):
+ _tk_unavailable = "cannot run without OS X gui process"
+ else: # not OS X
+ import tkinter
+ try:
+ tkinter.Button()
+ except tkinter.TclError as msg:
+ # assuming tk is not available
+ _tk_unavailable = "tk not available: %s" % msg
+
+ if _tk_unavailable:
+ raise unittest.SkipTest(_tk_unavailable)
+ return
def get_tk_root():
+ check_tk_availability() # raise exception if tk unavailable
try:
root = tkinter._default_root
except AttributeError:
diff --git a/Lib/tkinter/test/test_tkinter/test_font.py b/Lib/tkinter/test/test_tkinter/test_font.py
new file mode 100644
index 0000000..dfd630b
--- /dev/null
+++ b/Lib/tkinter/test/test_tkinter/test_font.py
@@ -0,0 +1,33 @@
+import unittest
+import tkinter
+from tkinter import font
+from test.support import requires, run_unittest
+import tkinter.test.support as support
+
+requires('gui')
+
+class FontTest(unittest.TestCase):
+
+ def setUp(self):
+ support.root_deiconify()
+
+ def tearDown(self):
+ support.root_withdraw()
+
+ def test_font_eq(self):
+ fontname = "TkDefaultFont"
+ try:
+ f = font.Font(name=fontname, exists=True)
+ except tkinter._tkinter.TclError:
+ f = font.Font(name=fontname, exists=False)
+ font1 = font.nametofont(fontname)
+ font2 = font.nametofont(fontname)
+ self.assertIsNot(font1, font2)
+ self.assertEqual(font1, font2)
+ self.assertNotEqual(font1, font1.copy())
+ self.assertNotEqual(font1, 0)
+
+tests_gui = (FontTest, )
+
+if __name__ == "__main__":
+ run_unittest(*tests_gui)
diff --git a/Lib/tkinter/test/test_tkinter/test_loadtk.py b/Lib/tkinter/test/test_tkinter/test_loadtk.py
index 8f1a085..bab7bcd 100644
--- a/Lib/tkinter/test/test_tkinter/test_loadtk.py
+++ b/Lib/tkinter/test/test_tkinter/test_loadtk.py
@@ -31,7 +31,8 @@ class TkLoadTest(unittest.TestCase):
# doesn't actually carry through to the process level
# because they don't support unsetenv
# If that's the case, abort.
- display = os.popen('echo $DISPLAY').read().strip()
+ with os.popen('echo $DISPLAY') as pipe:
+ display = pipe.read().strip()
if display:
return
diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py
new file mode 100644
index 0000000..d325b31
--- /dev/null
+++ b/Lib/tkinter/test/test_tkinter/test_misc.py
@@ -0,0 +1,45 @@
+import unittest
+import tkinter
+from tkinter import ttk
+from test import support
+
+support.requires('gui')
+
+class MiscTest(unittest.TestCase):
+
+ def setUp(self):
+ self.root = ttk.setup_master()
+
+ def test_tk_setPalette(self):
+ root = self.root
+ root.tk_setPalette('black')
+ self.assertEqual(root['background'], 'black')
+ root.tk_setPalette('white')
+ self.assertEqual(root['background'], 'white')
+ self.assertRaisesRegex(tkinter.TclError,
+ '^unknown color name "spam"$',
+ root.tk_setPalette, 'spam')
+
+ root.tk_setPalette(background='black')
+ self.assertEqual(root['background'], 'black')
+ root.tk_setPalette(background='blue', highlightColor='yellow')
+ self.assertEqual(root['background'], 'blue')
+ self.assertEqual(root['highlightcolor'], 'yellow')
+ root.tk_setPalette(background='yellow', highlightColor='blue')
+ self.assertEqual(root['background'], 'yellow')
+ self.assertEqual(root['highlightcolor'], 'blue')
+ self.assertRaisesRegex(tkinter.TclError,
+ '^unknown color name "spam"$',
+ root.tk_setPalette, background='spam')
+ self.assertRaisesRegex(tkinter.TclError,
+ '^must specify a background color$',
+ root.tk_setPalette, spam='white')
+ self.assertRaisesRegex(tkinter.TclError,
+ '^must specify a background color$',
+ root.tk_setPalette, highlightColor='blue')
+
+
+tests_gui = (MiscTest, )
+
+if __name__ == "__main__":
+ support.run_unittest(*tests_gui)
diff --git a/Lib/tkinter/test/test_ttk/test_functions.py b/Lib/tkinter/test/test_ttk/test_functions.py
index 2303e4c..0d8df16 100644
--- a/Lib/tkinter/test/test_ttk/test_functions.py
+++ b/Lib/tkinter/test/test_ttk/test_functions.py
@@ -49,13 +49,17 @@ class InternalFunctionsTest(unittest.TestCase):
ttk._format_optdict({'test': {'left': 'as is'}}),
{'-test': {'left': 'as is'}})
- # check script formatting and untouched value(s)
+ # check script formatting
check_against(
ttk._format_optdict(
- {'test': [1, -1, '', '2m', 0], 'nochange1': 3,
- 'nochange2': 'abc def'}, script=True),
- {'-test': '{1 -1 {} 2m 0}', '-nochange1': 3,
- '-nochange2': 'abc def' })
+ {'test': [1, -1, '', '2m', 0], 'test2': 3,
+ 'test3': '', 'test4': 'abc def',
+ 'test5': '"abc"', 'test6': '{}',
+ 'test7': '} -spam {'}, script=True),
+ {'-test': '{1 -1 {} 2m 0}', '-test2': '3',
+ '-test3': '{}', '-test4': '{abc def}',
+ '-test5': '{"abc"}', '-test6': r'\{\}',
+ '-test7': r'\}\ -spam\ \{'})
opts = {'αβγ': True, 'á': False}
orig_opts = opts.copy()
@@ -69,6 +73,32 @@ class InternalFunctionsTest(unittest.TestCase):
ttk._format_optdict(
{'option': ('one two', 'three')}),
{'-option': '{one two} three'})
+ check_against(
+ ttk._format_optdict(
+ {'option': ('one\ttwo', 'three')}),
+ {'-option': '{one\ttwo} three'})
+
+ # passing empty strings inside a tuple/list
+ check_against(
+ ttk._format_optdict(
+ {'option': ('', 'one')}),
+ {'-option': '{} one'})
+
+ # passing values with braces inside a tuple/list
+ check_against(
+ ttk._format_optdict(
+ {'option': ('one} {two', 'three')}),
+ {'-option': r'one\}\ \{two three'})
+
+ # passing quoted strings inside a tuple/list
+ check_against(
+ ttk._format_optdict(
+ {'option': ('"one"', 'two')}),
+ {'-option': '{"one"} two'})
+ check_against(
+ ttk._format_optdict(
+ {'option': ('{one}', 'two')}),
+ {'-option': r'\{one\} two'})
# ignore an option
amount_opts = len(ttk._format_optdict(opts, ignore=('á'))) / 2
diff --git a/Lib/tkinter/test/test_ttk/test_widgets.py b/Lib/tkinter/test/test_ttk/test_widgets.py
index 35824ea..45a686a 100644
--- a/Lib/tkinter/test/test_ttk/test_widgets.py
+++ b/Lib/tkinter/test/test_ttk/test_widgets.py
@@ -1,7 +1,9 @@
import unittest
import tkinter
+import os
from tkinter import ttk
from test.support import requires, run_unittest
+import sys
import tkinter.test.support as support
from tkinter.test.test_ttk.test_functions import MockTclObj, MockStateSpec
@@ -187,6 +189,14 @@ class ComboboxTest(unittest.TestCase):
self.combo.configure(values=[1, '', 2])
self.assertEqual(self.combo['values'], ('1', '', '2'))
+ # testing values with spaces
+ self.combo['values'] = ['a b', 'a\tb', 'a\nb']
+ self.assertEqual(self.combo['values'], ('a b', 'a\tb', 'a\nb'))
+
+ # testing values with special characters
+ self.combo['values'] = [r'a\tb', '"a"', '} {']
+ self.assertEqual(self.combo['values'], (r'a\tb', '"a"', '} {'))
+
# out of range
self.assertRaises(tkinter.TclError, self.combo.current,
len(self.combo['values']))
@@ -560,11 +570,19 @@ class NotebookTest(unittest.TestCase):
self.nb.pack()
self.nb.wait_visibility()
- self.assertEqual(self.nb.tab('@5,5'), self.nb.tab('current'))
+ if sys.platform == 'darwin':
+ tb_idx = "@20,5"
+ else:
+ tb_idx = "@5,5"
+ self.assertEqual(self.nb.tab(tb_idx), self.nb.tab('current'))
for i in range(5, 100, 5):
- if self.nb.tab('@%d, 5' % i, text=None) == 'a':
- break
+ try:
+ if self.nb.tab('@%d, 5' % i, text=None) == 'a':
+ break
+ except tkinter.TclError:
+ pass
+
else:
self.fail("Tab with text 'a' not found")
@@ -721,7 +739,10 @@ class NotebookTest(unittest.TestCase):
self.nb.enable_traversal()
self.nb.focus_force()
support.simulate_mouse_click(self.nb, 5, 5)
- self.nb.event_generate('<Alt-a>')
+ if sys.platform == 'darwin':
+ self.nb.event_generate('<Option-a>')
+ else:
+ self.nb.event_generate('<Alt-a>')
self.assertEqual(self.nb.select(), str(self.child1))
@@ -925,7 +946,8 @@ class TreeviewTest(unittest.TestCase):
self.assertRaises(tkinter.TclError, self.tv.heading, '#0',
anchor=1)
-
+ # XXX skipping for now; should be fixed to work with newer ttk
+ @unittest.skip("skipping pending resolution of Issue #10734")
def test_heading_callback(self):
def simulate_heading_click(x, y):
support.simulate_mouse_click(self.tv, x, y)
diff --git a/Lib/tkinter/tix.py b/Lib/tkinter/tix.py
index b105278..99f9fff 100644
--- a/Lib/tkinter/tix.py
+++ b/Lib/tkinter/tix.py
@@ -46,6 +46,21 @@ BALLOON = 'balloon'
AUTO = 'auto'
ACROSSTOP = 'acrosstop'
+# A few useful constants for the Grid widget
+ASCII = 'ascii'
+CELL = 'cell'
+COLUMN = 'column'
+DECREASING = 'decreasing'
+INCREASING = 'increasing'
+INTEGER = 'integer'
+MAIN = 'main'
+MAX = 'max'
+REAL = 'real'
+ROW = 'row'
+S_REGION = 's-region'
+X_REGION = 'x-region'
+Y_REGION = 'y-region'
+
# Some constants used by Tkinter dooneevent()
TCL_DONT_WAIT = 1 << 1
TCL_WINDOW_EVENTS = 1 << 2
@@ -390,7 +405,7 @@ class TixWidget(tkinter.Widget):
elif kw: cnf = kw
options = ()
for k, v in cnf.items():
- if hasattr(v, '__call__'):
+ if callable(v):
v = self._register(v)
options = options + ('-'+k, v)
return master.tk.call(('image', 'create', imgtype,) + options)
@@ -850,7 +865,7 @@ class FileEntry(TixWidget):
# FIXME: return python object
pass
-class HList(TixWidget):
+class HList(TixWidget, XView, YView):
"""HList - Hierarchy display widget can be used to display any data
that have a hierarchical structure, for example, file system directory
trees. The list entries are indented and connected by branch lines
@@ -961,6 +976,10 @@ class HList(TixWidget):
def info_anchor(self):
return self.tk.call(self._w, 'info', 'anchor')
+ def info_bbox(self, entry):
+ return self._getints(
+ self.tk.call(self._w, 'info', 'bbox', entry)) or None
+
def info_children(self, entry=None):
c = self.tk.call(self._w, 'info', 'children', entry)
return self.tk.splitlist(c)
@@ -968,6 +987,12 @@ class HList(TixWidget):
def info_data(self, entry):
return self.tk.call(self._w, 'info', 'data', entry)
+ def info_dragsite(self):
+ return self.tk.call(self._w, 'info', 'dragsite')
+
+ def info_dropsite(self):
+ return self.tk.call(self._w, 'info', 'dropsite')
+
def info_exists(self, entry):
return self.tk.call(self._w, 'info', 'exists', entry)
@@ -1037,12 +1062,6 @@ class HList(TixWidget):
def show_entry(self, entry):
return self.tk.call(self._w, 'show', 'entry', entry)
- def xview(self, *args):
- self.tk.call(self._w, 'xview', *args)
-
- def yview(self, *args):
- self.tk.call(self._w, 'yview', *args)
-
class InputOnly(TixWidget):
"""InputOnly - Invisible widget. Unix only.
@@ -1241,11 +1260,8 @@ class PanedWindow(TixWidget):
self.tk.call(self._w, 'paneconfigure', entry, *self._options(cnf, kw))
def panes(self):
- names = self.tk.call(self._w, 'panes')
- ret = []
- for x in names:
- ret.append(self.subwidget(x))
- return ret
+ names = self.tk.splitlist(self.tk.call(self._w, 'panes'))
+ return [self.subwidget(x) for x in names]
class PopupMenu(TixWidget):
"""PopupMenu widget can be used as a replacement of the tk_popup command.
@@ -1419,7 +1435,7 @@ class StdButtonBox(TixWidget):
if name in self.subwidget_list:
self.tk.call(self._w, 'invoke', name)
-class TList(TixWidget):
+class TList(TixWidget, XView, YView):
"""TList - Hierarchy display widget which can be
used to display data in a tabular format. The list entries of a TList
widget are similar to the entries in the Tk listbox widget. The main
@@ -1502,12 +1518,6 @@ class TList(TixWidget):
def selection_set(self, first, last=None):
self.tk.call(self._w, 'selection', 'set', first, last)
- def xview(self, *args):
- self.tk.call(self._w, 'xview', *args)
-
- def yview(self, *args):
- self.tk.call(self._w, 'yview', *args)
-
class Tree(TixWidget):
"""Tree - The tixTree widget can be used to display hierarchical
data in a tree form. The user can adjust
@@ -1544,8 +1554,8 @@ class Tree(TixWidget):
'''This command is used to indicate whether the entry given by
entryPath has children entries and whether the children are visible. mode
must be one of open, close or none. If mode is set to open, a (+)
- indicator is drawn next the the entry. If mode is set to close, a (-)
- indicator is drawn next the the entry. If mode is set to none, no
+ indicator is drawn next the entry. If mode is set to close, a (-)
+ indicator is drawn next the entry. If mode is set to none, no
indicators will be drawn for this entry. The default mode is none. The
open mode indicates the entry has hidden children and this entry can be
opened by the user. The close mode indicates that all the children of the
@@ -1563,7 +1573,7 @@ class CheckList(TixWidget):
# FIXME: It should inherit -superclass tixTree
def __init__(self, master=None, cnf={}, **kw):
TixWidget.__init__(self, master, 'tixCheckList',
- ['options'], cnf, kw)
+ ['options', 'radio'], cnf, kw)
self.subwidget_list['hlist'] = _dummyHList(self, 'hlist')
self.subwidget_list['vsb'] = _dummyScrollbar(self, 'vsb')
self.subwidget_list['hsb'] = _dummyScrollbar(self, 'hsb')
@@ -1777,7 +1787,7 @@ class CObjView(TixWidget):
pass
-class Grid(TixWidget):
+class Grid(TixWidget, XView, YView):
'''The Tix Grid command creates a new window and makes it into a
tixGrid widget. Additional options, may be specified on the command
line or in the option database to configure aspects such as its cursor
@@ -1801,16 +1811,21 @@ class Grid(TixWidget):
TixWidget.__init__(self, master, 'tixGrid', static, cnf, kw)
# valid options as of Tk 8.4
- # anchor, bdtype, cget, configure, delete, dragsite, dropsite, entrycget, edit
- # entryconfigure, format, geometryinfo, info, index, move, nearest, selection
- # set, size, unset, xview, yview
- # def anchor option ?args ...?
+ # anchor, bdtype, cget, configure, delete, dragsite, dropsite, entrycget,
+ # edit, entryconfigure, format, geometryinfo, info, index, move, nearest,
+ # selection, set, size, unset, xview, yview
+ def anchor_clear(self):
+ """Removes the selection anchor."""
+ self.tk.call(self, 'anchor', 'clear')
+
def anchor_get(self):
"Get the (x,y) coordinate of the current anchor cell"
return self._getints(self.tk.call(self, 'anchor', 'get'))
- # def bdtype
- # def delete dim from ?to?
+ def anchor_set(self, x, y):
+ """Set the selection anchor to the cell at (x, y)."""
+ self.tk.call(self, 'anchor', 'set', x, y)
+
def delete_row(self, from_, to=None):
"""Delete rows between from_ and to inclusive.
If to is not provided, delete only row at from_"""
@@ -1818,6 +1833,7 @@ class Grid(TixWidget):
self.tk.call(self, 'delete', 'row', from_)
else:
self.tk.call(self, 'delete', 'row', from_, to)
+
def delete_column(self, from_, to=None):
"""Delete columns between from_ and to inclusive.
If to is not provided, delete only column at from_"""
@@ -1825,26 +1841,49 @@ class Grid(TixWidget):
self.tk.call(self, 'delete', 'column', from_)
else:
self.tk.call(self, 'delete', 'column', from_, to)
- # def edit apply
- # def edit set x y
+
+ def edit_apply(self):
+ """If any cell is being edited, de-highlight the cell and applies
+ the changes."""
+ self.tk.call(self, 'edit', 'apply')
+
+ def edit_set(self, x, y):
+ """Highlights the cell at (x, y) for editing, if the -editnotify
+ command returns True for this cell."""
+ self.tk.call(self, 'edit', 'set', x, y)
def entrycget(self, x, y, option):
"Get the option value for cell at (x,y)"
+ if option and option[0] != '-':
+ option = '-' + option
return self.tk.call(self, 'entrycget', x, y, option)
- def entryconfigure(self, x, y, **kw):
- return self.tk.call(self, 'entryconfigure', x, y, *self._options(None, kw))
+ def entryconfigure(self, x, y, cnf=None, **kw):
+ return self._configure(('entryconfigure', x, y), cnf, kw)
+
# def format
# def index
def info_exists(self, x, y):
"Return True if display item exists at (x,y)"
- return bool(int(self.tk.call(self, 'info', 'exists', x, y)))
+ return self._getboolean(self.tk.call(self, 'info', 'exists', x, y))
def info_bbox(self, x, y):
# This seems to always return '', at least for 'text' displayitems
return self.tk.call(self, 'info', 'bbox', x, y)
+ def move_column(self, from_, to, offset):
+ """Moves the range of columns from position FROM through TO by
+ the distance indicated by OFFSET. For example, move_column(2, 4, 1)
+ moves the columns 2,3,4 to columns 3,4,5."""
+ self.tk.call(self, 'move', 'column', from_, to, offset)
+
+ def move_row(self, from_, to, offset):
+ """Moves the range of rows from position FROM through TO by
+ the distance indicated by OFFSET.
+ For example, move_row(2, 4, 1) moves the rows 2,3,4 to rows 3,4,5."""
+ self.tk.call(self, 'move', 'row', from_, to, offset)
+
def nearest(self, x, y):
"Return coordinate of cell nearest pixel coordinate (x,y)"
return self._getints(self.tk.call(self, 'nearest', x, y))
@@ -1854,7 +1893,6 @@ class Grid(TixWidget):
# def selection includes
# def selection set
# def selection toggle
- # def move dim from to offset
def set(self, x, y, itemtype=None, **kw):
args= self._options(self.cnf, kw)
@@ -1862,24 +1900,61 @@ class Grid(TixWidget):
args= ('-itemtype', itemtype) + args
self.tk.call(self, 'set', x, y, *args)
- # def size dim index ?option value ...?
- # def unset x y
-
- def xview(self):
- return self._getdoubles(self.tk.call(self, 'xview'))
- def xview_moveto(self, fraction):
- self.tk.call(self,'xview', 'moveto', fraction)
- def xview_scroll(self, count, what="units"):
- "Scroll right (count>0) or left <count> of units|pages"
- self.tk.call(self, 'xview', 'scroll', count, what)
-
- def yview(self):
- return self._getdoubles(self.tk.call(self, 'yview'))
- def yview_moveto(self, fraction):
- self.tk.call(self,'ysview', 'moveto', fraction)
- def yview_scroll(self, count, what="units"):
- "Scroll down (count>0) or up <count> of units|pages"
- self.tk.call(self, 'yview', 'scroll', count, what)
+ def size_column(self, index, **kw):
+ """Queries or sets the size of the column given by
+ INDEX. INDEX may be any non-negative
+ integer that gives the position of a given column.
+ INDEX can also be the string "default"; in this case, this command
+ queries or sets the default size of all columns.
+ When no option-value pair is given, this command returns a tuple
+ containing the current size setting of the given column. When
+ option-value pairs are given, the corresponding options of the
+ size setting of the given column are changed. Options may be one
+ of the follwing:
+ pad0 pixels
+ Specifies the paddings to the left of a column.
+ pad1 pixels
+ Specifies the paddings to the right of a column.
+ size val
+ Specifies the width of a column. Val may be:
+ "auto" -- the width of the column is set to the
+ width of the widest cell in the column;
+ a valid Tk screen distance unit;
+ or a real number following by the word chars
+ (e.g. 3.4chars) that sets the width of the column to the
+ given number of characters."""
+ return self.tk.split(self.tk.call(self._w, 'size', 'column', index,
+ *self._options({}, kw)))
+
+ def size_row(self, index, **kw):
+ """Queries or sets the size of the row given by
+ INDEX. INDEX may be any non-negative
+ integer that gives the position of a given row .
+ INDEX can also be the string "default"; in this case, this command
+ queries or sets the default size of all rows.
+ When no option-value pair is given, this command returns a list con-
+ taining the current size setting of the given row . When option-value
+ pairs are given, the corresponding options of the size setting of the
+ given row are changed. Options may be one of the follwing:
+ pad0 pixels
+ Specifies the paddings to the top of a row.
+ pad1 pixels
+ Specifies the paddings to the bottom of a row.
+ size val
+ Specifies the height of a row. Val may be:
+ "auto" -- the height of the row is set to the
+ height of the highest cell in the row;
+ a valid Tk screen distance unit;
+ or a real number following by the word chars
+ (e.g. 3.4chars) that sets the height of the row to the
+ given number of characters."""
+ return self.tk.split(self.tk.call(
+ self, 'size', 'row', index, *self._options({}, kw)))
+
+ def unset(self, x, y):
+ """Clears the cell at (x, y) by removing its display item."""
+ self.tk.call(self._w, 'unset', x, y)
+
class ScrolledGrid(Grid):
'''Scrolled Grid widgets'''
diff --git a/Lib/tkinter/ttk.py b/Lib/tkinter/ttk.py
index 9213b62..6cd4ea6 100644
--- a/Lib/tkinter/ttk.py
+++ b/Lib/tkinter/ttk.py
@@ -26,8 +26,7 @@ __all__ = ["Button", "Checkbutton", "Combobox", "Entry", "Frame", "Label",
"tclobjs_to_py", "setup_master"]
import tkinter
-
-_flatten = tkinter._flatten
+from tkinter import _flatten, _join, _stringify
# Verify if Tk is new enough to not need the Tile package
_REQUIRE_TILE = True if tkinter.TkVersion < 8.5 else False
@@ -37,7 +36,7 @@ def _load_tile(master):
import os
tilelib = os.environ.get('TILE_LIBRARY')
if tilelib:
- # append custom tile path to the the list of directories that
+ # append custom tile path to the list of directories that
# Tcl uses when attempting to resolve packages with the package
# command
master.tk.eval(
@@ -47,40 +46,55 @@ def _load_tile(master):
master.tk.eval('package require tile') # TclError may be raised here
master._tile_loaded = True
+def _format_optvalue(value, script=False):
+ """Internal function."""
+ if script:
+ # if caller passes a Tcl script to tk.call, all the values need to
+ # be grouped into words (arguments to a command in Tcl dialect)
+ value = _stringify(value)
+ elif isinstance(value, (list, tuple)):
+ value = _join(value)
+ return value
+
def _format_optdict(optdict, script=False, ignore=None):
"""Formats optdict to a tuple to pass it to tk.call.
E.g. (script=False):
{'foreground': 'blue', 'padding': [1, 2, 3, 4]} returns:
('-foreground', 'blue', '-padding', '1 2 3 4')"""
- format = "%s" if not script else "{%s}"
opts = []
for opt, value in optdict.items():
- if ignore and opt in ignore:
- continue
-
- if isinstance(value, (list, tuple)):
- v = []
- for val in value:
- if isinstance(val, str):
- v.append(str(val) if val else '{}')
- else:
- v.append(str(val))
-
- # format v according to the script option, but also check for
- # space in any value in v in order to group them correctly
- value = format % ' '.join(
- ('{%s}' if ' ' in val else '%s') % val for val in v)
-
- if script and value == '':
- value = '{}' # empty string in Python is equivalent to {} in Tcl
+ if not ignore or opt not in ignore:
+ opts.append("-%s" % opt)
+ if value is not None:
+ opts.append(_format_optvalue(value, script))
- opts.append(("-%s" % opt, value))
-
- # Remember: _flatten skips over None
return _flatten(opts)
+def _mapdict_values(items):
+ # each value in mapdict is expected to be a sequence, where each item
+ # is another sequence containing a state (or several) and a value
+ # E.g. (script=False):
+ # [('active', 'selected', 'grey'), ('focus', [1, 2, 3, 4])]
+ # returns:
+ # ['active selected', 'grey', 'focus', [1, 2, 3, 4]]
+ opt_val = []
+ for *state, val in items:
+ # hacks for bakward compatibility
+ state[0] # raise IndexError if empty
+ if len(state) == 1:
+ # if it is empty (something that evaluates to False), then
+ # format it to Tcl code to denote the "normal" state
+ state = state[0] or ''
+ else:
+ # group multiple states
+ state = ' '.join(state) # raise TypeError if not str
+ opt_val.append(state)
+ if val is not None:
+ opt_val.append(val)
+ return opt_val
+
def _format_mapdict(mapdict, script=False):
"""Formats mapdict to pass it to tk.call.
@@ -90,32 +104,11 @@ def _format_mapdict(mapdict, script=False):
returns:
('-expand', '{active selected} grey focus {1, 2, 3, 4}')"""
- # if caller passes a Tcl script to tk.call, all the values need to
- # be grouped into words (arguments to a command in Tcl dialect)
- format = "%s" if not script else "{%s}"
opts = []
for opt, value in mapdict.items():
-
- opt_val = []
- # each value in mapdict is expected to be a sequence, where each item
- # is another sequence containing a state (or several) and a value
- for statespec in value:
- state, val = statespec[:-1], statespec[-1]
-
- if len(state) > 1: # group multiple states
- state = "{%s}" % ' '.join(state)
- else: # single state
- # if it is empty (something that evaluates to False), then
- # format it to Tcl code to denote the "normal" state
- state = state[0] or '{}'
-
- if isinstance(val, (list, tuple)): # val needs to be grouped
- val = "{%s}" % ' '.join(map(str, val))
-
- opt_val.append("%s %s" % (state, val))
-
- opts.append(("-%s" % opt, format % ' '.join(opt_val)))
+ opts.extend(("-%s" % opt,
+ _format_optvalue(_mapdict_values(value), script)))
return _flatten(opts)
@@ -129,7 +122,7 @@ def _format_elemcreate(etype, script=False, *args, **kw):
iname = args[0]
# next args, if any, are statespec/value pairs which is almost
# a mapdict, but we just need the value
- imagespec = _format_mapdict({None: args[1:]})[1]
+ imagespec = _join(_mapdict_values(args[1:]))
spec = "%s %s" % (iname, imagespec)
else:
@@ -138,7 +131,7 @@ def _format_elemcreate(etype, script=False, *args, **kw):
# themed styles on Windows XP and Vista.
# Availability: Tk 8.6, Windows XP and Vista.
class_name, part_id = args[:2]
- statemap = _format_mapdict({None: args[2:]})[1]
+ statemap = _join(_mapdict_values(args[2:]))
spec = "%s %s %s" % (class_name, part_id, statemap)
opts = _format_optdict(kw, script)
@@ -148,11 +141,11 @@ def _format_elemcreate(etype, script=False, *args, **kw):
# otherwise it will clone {} (empty element)
spec = args[0] # theme name
if len(args) > 1: # elementfrom specified
- opts = (args[1], )
+ opts = (_format_optvalue(args[1], script),)
if script:
spec = '{%s}' % spec
- opts = ' '.join(map(str, opts))
+ opts = ' '.join(opts)
return spec, opts
@@ -189,7 +182,7 @@ def _format_layoutlist(layout, indent=0, indent_size=2):
for layout_elem in layout:
elem, opts = layout_elem
opts = opts or {}
- fopts = ' '.join(map(str, _format_optdict(opts, True, "children")))
+ fopts = ' '.join(_format_optdict(opts, True, ("children",)))
head = "%s%s%s" % (' ' * indent, elem, (" %s" % fopts) if fopts else '')
if "children" in opts:
@@ -215,11 +208,11 @@ def _script_from_settings(settings):
for name, opts in settings.items():
# will format specific keys according to Tcl code
if opts.get('configure'): # format 'configure'
- s = ' '.join(map(str, _format_optdict(opts['configure'], True)))
+ s = ' '.join(_format_optdict(opts['configure'], True))
script.append("ttk::style configure %s %s;" % (name, s))
if opts.get('map'): # format 'map'
- s = ' '.join(map(str, _format_mapdict(opts['map'], True)))
+ s = ' '.join(_format_mapdict(opts['map'], True))
script.append("ttk::style map %s %s;" % (name, s))
if 'layout' in opts: # format 'layout' which may be empty
@@ -706,30 +699,9 @@ class Combobox(Entry):
exportselection, justify, height, postcommand, state,
textvariable, values, width
"""
- # The "values" option may need special formatting, so leave to
- # _format_optdict the responsibility to format it
- if "values" in kw:
- kw["values"] = _format_optdict({'v': kw["values"]})[1]
-
Entry.__init__(self, master, "ttk::combobox", **kw)
- def __setitem__(self, item, value):
- if item == "values":
- value = _format_optdict({item: value})[1]
-
- Entry.__setitem__(self, item, value)
-
-
- def configure(self, cnf=None, **kw):
- """Custom Combobox configure, created to properly format the values
- option."""
- if "values" in kw:
- kw["values"] = _format_optdict({'v': kw["values"]})[1]
-
- return Entry.configure(self, cnf, **kw)
-
-
def current(self, newindex=None):
"""If newindex is supplied, sets the combobox value to the
element at position newindex in the list of values. Otherwise,
@@ -1170,7 +1142,7 @@ class Sizegrip(Widget):
Widget.__init__(self, master, "ttk::sizegrip", kw)
-class Treeview(Widget):
+class Treeview(Widget, tkinter.XView, tkinter.YView):
"""Ttk Treeview widget displays a hierarchical collection of items.
Each item has a textual label, an optional image, and an optional list
@@ -1253,7 +1225,7 @@ class Treeview(Widget):
def exists(self, item):
- """Returns True if the specified item is present in the three,
+ """Returns True if the specified item is present in the tree,
False otherwise."""
return bool(self.tk.call(self._w, "exists", item))
@@ -1480,16 +1452,6 @@ class Treeview(Widget):
return self.tk.call(self._w, "tag", "has", tagname, item)
- def xview(self, *args):
- """Query or modify horizontal position of the treeview."""
- return self.tk.call(self._w, "xview", *args)
-
-
- def yview(self, *args):
- """Query or modify vertical position of the treeview."""
- return self.tk.call(self._w, "yview", *args)
-
-
# Extensions
class LabeledScale(Frame):