summaryrefslogtreecommitdiff
path: root/Lib/tkinter/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/tkinter/__init__.py')
-rw-r--r--Lib/tkinter/__init__.py100
1 files changed, 20 insertions, 80 deletions
diff --git a/Lib/tkinter/__init__.py b/Lib/tkinter/__init__.py
index 21a560b5bf..c57ebd275d 100644
--- a/Lib/tkinter/__init__.py
+++ b/Lib/tkinter/__init__.py
@@ -775,9 +775,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,)
@@ -1336,6 +1333,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_):
@@ -1850,7 +1852,7 @@ class Tk(Misc, Wm):
import os
baseName = os.path.basename(sys.argv[0])
baseName, ext = os.path.splitext(baseName)
- if ext not in ('.py', '.pyc', '.pyo'):
+ if ext not in ('.py', '.pyc'):
baseName = baseName + ext
interactive = 0
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
@@ -2196,21 +2198,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.
@@ -2709,35 +2696,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)
@@ -2910,10 +2877,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."""
@@ -2931,10 +2902,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)
@@ -2969,14 +2940,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 !=."""
@@ -3854,35 +3817,12 @@ 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():
root = Tk()
text = "This is Tcl/Tk version %s" % TclVersion
- if TclVersion >= 8.1:
- text += "\nThis should be a cedilla: \xe7"
+ text += "\nThis should be a cedilla: \xe7"
label = Label(root, text=text)
label.pack()
test = Button(root, text="Click me!",