UPDATED: SEE BELOW
I ported the code for this purpose: http://www.stanford.edu/class/cs221/progAssignments/PA1/search.html (all source code is available as zip) from Python 2.x to 3.x. Please note: porting is not a destination, and only I try to update the code and avoid installing another version of Python ...
After the usual syntax corrections 2.x → 3.x (printing, collecting exceptions, etc.) and the realization that the module is Tkinternow known as Tkinter3.x (lower case) I ran into unfamiliar problems, with this fragment and several others such as:
def keys_pressed(d_o_e=tkinter.tkinter.dooneevent,d_w=tkinter.tkinter.DONT_WAIT)
Errors are of the type:
AttributeError: 'module' object has no attribute 'tkinter'
Code completion in my IDE and variable tracing really show that the module Tkinterdoes not have an attribute or subclass Tkinterunder which you can reference dooneeventor DONT_WAIT. However, there are several other links on the Internet for people using constructs such as
_tkinter.dooneevent(_tkinter.DONT_WAIT)
to move the main loop forward, but even referring to it, it still gives the same error.
Any ideas were greatly appreciated.
UPDATE: Referring to _root_window via lambda notation seems to work, since it no longer complains about pre-execution time in most cases. However, for my unprepared eye, this is mostly "magic", and therefore I do not know what this subsequent error says or how to get around it. Now the method looks like this: my changes in the first line:
def move_to(object, x, y=None, d_o_e=lambda arg: _root_window(arg), d_w=tkinter._tkinter.DONT_WAIT):
if y is None:
try: x, y = x
except: raise 'incomprehensible coordinates'
horiz = True
newCoords = []
current_x, current_y = _canvas.coords(object)[0:2]
for coord in _canvas.coords(object):
if horiz:
inc = x - current_x
else:
inc = y - current_y
horiz = not horiz
newCoords.append(coord + inc)
_canvas.coords(object, *newCoords)
d_o_e(d_w)
:
TypeError: 'Tk' object is not callable
, ( ).