[ python-Bugs-799428 ] tk_focusNext() fails

SourceForge.net noreply at sourceforge.net
Thu Jun 7 19:44:45 CEST 2007


Bugs item #799428, was opened at 2003-09-02 16:58
Message generated for change (Comment added) made by lither
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=799428&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Tkinter
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Perry Greenfield (perrygreenfield)
Assigned to: Nobody/Anonymous (nobody)
Summary: tk_focusNext() fails

Initial Comment:
Calls to the widget method tk_focusNext() fail with
"unsubscriptable object" error. Looking at the Tkinter.py 
code for the routine shows this statement:

name = self.tk.call('tk_focusNext', self._w)

(line 433)

which used to return a string in 2.2 but now returns
a "cmdName object". When this is passed to 
self._nametowidget(name), it fails when it tries to
subscript name (line 1006) since the object does
not support indexing. Perhaps str(name) or
name.string is more appropriate now? (when
that change is made, it works--well, I tested
name.string and that worked)

Perry Greenfield (perry at stsci.edu)

----------------------------------------------------------------------

Comment By: Rick Litherland (lither)
Date: 2007-06-07 12:44

Message:
Logged In: YES 
user_id=1797212
Originator: NO

This problem still persists, at least in Python 2.4. As noted by Perry
Greenfield, the same problem occurs in tk_focusPrev, and some other methods
as well. Rather than track down all such calls it would be easier to add
the line
    name = str(name)
at the top of the nametowidget method.

Rick Litherand.
lither at math.lsu.edu


----------------------------------------------------------------------

Comment By: David Douard (douardda)
Date: 2005-11-09 09:03

Message:
Logged In: YES 
user_id=692511

The problem is still not resolved for now (AFAIK).

Here is a very simple patch for Tkinter.py:

*** 432,442 ****
--- 432,446 ----
          to 0."""
          name = self.tk.call('tk_focusNext', self._w)
          if not name: return None
+         try: name=name.string
+         except: pass
          return self._nametowidget(name)
      def tk_focusPrev(self):
          """Return previous widget in the focus order. See
tk_focusNext for details."""
          name = self.tk.call('tk_focusPrev', self._w)
          if not name: return None
+         try: name=name.string
+         except: pass
          return self._nametowidget(name)
      def after(self, ms, func=None, *args):
          """Call function once after given time.

Note: I have made this (try/except) cause I have encountered
cases where "name" was still a string (well, at least with
Python 2.3.1).

David (david.douard*gmail.com)


----------------------------------------------------------------------

Comment By: Jeff Epler (jepler)
Date: 2003-09-07 10:23

Message:
Logged In: YES 
user_id=2772

Presumably, _nametowidget() should be modified to work properly with a
"cmdName object", rather than modifying each site that gets a
widget path from a tk command.  

----------------------------------------------------------------------

Comment By: Perry Greenfield (perrygreenfield)
Date: 2003-09-03 08:29

Message:
Logged In: YES 
user_id=252130

Presumably the same problem exists with tk_focusPrev.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=799428&group_id=5470


More information about the Python-bugs-list mailing list