diff options
Diffstat (limited to 'Lib/tkinter')
-rw-r--r-- | Lib/tkinter/__init__.py | 95 | ||||
-rw-r--r-- | Lib/tkinter/test/test_tkinter/test_misc.py | 5 | ||||
-rw-r--r-- | Lib/tkinter/test/test_tkinter/test_widgets.py | 7 |
3 files changed, 27 insertions, 80 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py index 75e5fb1..aaa2bfc 100644 --- a/Lib/tkinter/__init__.py +++ b/Lib/tkinter/__init__.py @@ -722,9 +722,6 @@ class Misc: """Raise this widget in the stacking order.""" self.tk.call('raise', self._w, aboveThis) lift = tkraise - def colormodel(self, value=None): - """Useless. Not implemented in Tk.""" - return self.tk.call('tk', 'colormodel', self._w, value) def winfo_atom(self, name, displayof=0): """Return integer which represents atom NAME.""" args = ('winfo', 'atom') + self._displayof(displayof) + (name,) @@ -1283,6 +1280,11 @@ class Misc: def __str__(self): """Return the window path name of this widget.""" return self._w + + def __repr__(self): + return '<%s.%s object %s>' % ( + self.__class__.__module__, self.__class__.__qualname__, self._w) + # Pack methods that apply to the master _noarg_ = ['_noarg_'] def pack_propagate(self, flag=_noarg_): @@ -2163,21 +2165,6 @@ class Button(Widget): """ Widget.__init__(self, master, 'button', cnf, kw) - def tkButtonEnter(self, *dummy): - self.tk.call('tkButtonEnter', self._w) - - def tkButtonLeave(self, *dummy): - self.tk.call('tkButtonLeave', self._w) - - def tkButtonDown(self, *dummy): - self.tk.call('tkButtonDown', self._w) - - def tkButtonUp(self, *dummy): - self.tk.call('tkButtonUp', self._w) - - def tkButtonInvoke(self, *dummy): - self.tk.call('tkButtonInvoke', self._w) - def flash(self): """Flash the button. @@ -2676,35 +2663,15 @@ class Menu(Widget): disabledforeground, fg, font, foreground, postcommand, relief, selectcolor, takefocus, tearoff, tearoffcommand, title, type.""" Widget.__init__(self, master, 'menu', cnf, kw) + def tk_popup(self, x, y, entry=""): + """Post the menu at position X,Y with entry ENTRY.""" + self.tk.call('tk_popup', self._w, x, y, entry) def tk_bindForTraversal(self): # obsolete since Tk 4.0 import warnings warnings.warn('tk_bindForTraversal() does nothing and ' 'will be removed in 3.6', DeprecationWarning, stacklevel=2) - def tk_mbPost(self): - self.tk.call('tk_mbPost', self._w) - def tk_mbUnpost(self): - self.tk.call('tk_mbUnpost') - def tk_traverseToMenu(self, char): - self.tk.call('tk_traverseToMenu', self._w, char) - def tk_traverseWithinMenu(self, char): - self.tk.call('tk_traverseWithinMenu', self._w, char) - def tk_getMenuButtons(self): - return self.tk.call('tk_getMenuButtons', self._w) - def tk_nextMenu(self, count): - self.tk.call('tk_nextMenu', count) - def tk_nextMenuEntry(self, count): - self.tk.call('tk_nextMenuEntry', count) - def tk_invokeMenu(self): - self.tk.call('tk_invokeMenu', self._w) - def tk_firstMenu(self): - self.tk.call('tk_firstMenu', self._w) - def tk_mbButtonDown(self): - self.tk.call('tk_mbButtonDown', self._w) - def tk_popup(self, x, y, entry=""): - """Post the menu at position X,Y with entry ENTRY.""" - self.tk.call('tk_popup', self._w, x, y, entry) def activate(self, index): """Activate entry at INDEX.""" self.tk.call(self._w, 'activate', index) @@ -2877,10 +2844,14 @@ class Scrollbar(Widget): relief, repeatdelay, repeatinterval, takefocus, troughcolor, width.""" Widget.__init__(self, master, 'scrollbar', cnf, kw) - def activate(self, index): - """Display the element at INDEX with activebackground and activerelief. - INDEX can be "arrow1","slider" or "arrow2".""" - self.tk.call(self._w, 'activate', index) + def activate(self, index=None): + """Marks the element indicated by index as active. + The only index values understood by this method are "arrow1", + "slider", or "arrow2". If any other value is specified then no + element of the scrollbar will be active. If index is not specified, + the method returns the name of the element that is currently active, + or None if no element is active.""" + return self.tk.call(self._w, 'activate', index) or None def delta(self, deltax, deltay): """Return the fractional change of the scrollbar setting if it would be moved by DELTAX or DELTAY pixels.""" @@ -2898,10 +2869,10 @@ class Scrollbar(Widget): """Return the current fractional values (upper and lower end) of the slider position.""" return self._getdoubles(self.tk.call(self._w, 'get')) - def set(self, *args): + def set(self, first, last): """Set the fractional values of the slider position (upper and lower ends as value between 0 and 1).""" - self.tk.call((self._w, 'set') + args) + self.tk.call(self._w, 'set', first, last) @@ -2936,14 +2907,6 @@ class Text(Widget, XView, YView): box of the visible part of the character at the given index.""" return self._getints( self.tk.call(self._w, 'bbox', index)) or None - def tk_textSelectTo(self, index): - self.tk.call('tk_textSelectTo', self._w, index) - def tk_textBackspace(self): - self.tk.call('tk_textBackspace', self._w) - def tk_textIndexCloser(self, a, b, c): - self.tk.call('tk_textIndexCloser', self._w, a, b, c) - def tk_textResetAnchor(self, index): - self.tk.call('tk_textResetAnchor', self._w, index) def compare(self, index1, op, index2): """Return whether between index INDEX1 and index INDEX2 the relation OP is satisfied. OP is one of <, <=, ==, >=, >, or !=.""" @@ -3821,28 +3784,6 @@ class PanedWindow(Widget): """Returns an ordered list of the child panes.""" return self.tk.splitlist(self.tk.call(self._w, 'panes')) -###################################################################### -# Extensions: - -class Studbutton(Button): - def __init__(self, master=None, cnf={}, **kw): - Widget.__init__(self, master, 'studbutton', cnf, kw) - self.bind('<Any-Enter>', self.tkButtonEnter) - self.bind('<Any-Leave>', self.tkButtonLeave) - self.bind('<1>', self.tkButtonDown) - self.bind('<ButtonRelease-1>', self.tkButtonUp) - -class Tributton(Button): - def __init__(self, master=None, cnf={}, **kw): - Widget.__init__(self, master, 'tributton', cnf, kw) - self.bind('<Any-Enter>', self.tkButtonEnter) - self.bind('<Any-Leave>', self.tkButtonLeave) - self.bind('<1>', self.tkButtonDown) - self.bind('<ButtonRelease-1>', self.tkButtonUp) - self['fg'] = self['bg'] - self['activebackground'] = self['bg'] - -###################################################################### # Test: def _test(): diff --git a/Lib/tkinter/test/test_tkinter/test_misc.py b/Lib/tkinter/test/test_tkinter/test_misc.py index d325b31..46f5170 100644 --- a/Lib/tkinter/test/test_tkinter/test_misc.py +++ b/Lib/tkinter/test/test_tkinter/test_misc.py @@ -10,6 +10,11 @@ class MiscTest(unittest.TestCase): def setUp(self): self.root = ttk.setup_master() + def test_repr(self): + t = tkinter.Toplevel(self.root, name='top') + f = tkinter.Frame(t, name='child') + self.assertEqual(repr(f), '<tkinter.Frame object .top.child>') + def test_tk_setPalette(self): root = self.root root.tk_setPalette('black') diff --git a/Lib/tkinter/test/test_tkinter/test_widgets.py b/Lib/tkinter/test/test_tkinter/test_widgets.py index c902997..6e3836f 100644 --- a/Lib/tkinter/test/test_tkinter/test_widgets.py +++ b/Lib/tkinter/test/test_tkinter/test_widgets.py @@ -920,8 +920,9 @@ class ScrollbarTest(AbstractWidgetTest, unittest.TestCase): sb = self.create() for e in ('arrow1', 'slider', 'arrow2'): sb.activate(e) + self.assertEqual(sb.activate(), e) sb.activate('') - self.assertRaises(TypeError, sb.activate) + self.assertIsNone(sb.activate()) self.assertRaises(TypeError, sb.activate, 'arrow1', 'arrow2') def test_set(self): @@ -931,8 +932,8 @@ class ScrollbarTest(AbstractWidgetTest, unittest.TestCase): self.assertRaises(TclError, sb.set, 'abc', 'def') self.assertRaises(TclError, sb.set, 0.6, 'def') self.assertRaises(TclError, sb.set, 0.6, None) - self.assertRaises(TclError, sb.set, 0.6) - self.assertRaises(TclError, sb.set, 0.6, 0.7, 0.8) + self.assertRaises(TypeError, sb.set, 0.6) + self.assertRaises(TypeError, sb.set, 0.6, 0.7, 0.8) @add_standard_options(StandardOptionsTests) |