tkinter woes when porting 2.x code to 3.x, 'tkinter' module attribute doesn't exist

后端 未结 1 1064
小蘑菇
小蘑菇 2021-01-12 09:19

UPDATED: SEE BELOW

I\'ve been porting the code for this assignment: http://www.stanford.edu/class/cs221/progAssignments/PA1/search.html (the entire source code is

相关标签:
1条回答
  • 2021-01-12 10:07

    It appears Tkinter.tkinter was changed to tkinter._tkinter in Python 3. Compare these docs from Python 2 with these from Python 3. Also, dooneevent is no longer in tkinter._tkinter, but is still a member of the Tk (aka root) object.

    So change your code to

    def keys_pressed(d_o_e=lambda arg: _root_window.dooneevent(arg),
            d_w=tkinter._tkinter.DONT_WAIT):
    

    This takes advantage of the fact that in your linked code _root_window is global, so while _root_window is not available when the class is defined, it will be available when the lambda is run.

    0 讨论(0)
提交回复
热议问题