1. 遇到的问题
在学习Python的标准库tkinter的时候,教程用的是Python2.7 , 而我使用的是的Python3.4。按照教程加载tkMessageBox库,发现居然没有这个库。猜想应该是把tkMessageBox的名字给换成别的了。
2. 问题的解决
上Python官网去查看想是否有相关信息。找到了以下信息,就猜测的那样是把命名给换了。tkMessageBox名字换成了tkinter.messagebox。
Python 3.4 tk支持库描述
tkinter.scrolledtext
Text widget with a vertical scroll bar built in.
tkinter.colorchooser
Dialog to let the user choose a color.
tkinter.commondialog
Base class for the dialogs defined in the other modules listed here.
tkinter.filedialog
Common dialogs to allow the user to specify a file to open or save.
tkinter.font
Utilities to help work with fonts.
tkinter.messagebox
Access to standard Tk dialog boxes.
tkinter.simpledialog
Basic dialogs and convenience functions.
tkinter.dnd
Drag-and-drop support for tkinter.
turtle
Turtle graphics in a Tk window.
python2.7 tk支持库描述的描述
ScrolledText
Text widget with a vertical scroll bar built in.
tkColorChooser
Dialog to let the user choose a color.
tkCommonDialog
Base class for the dialogs defined in the other modules listed here.
tkFileDialog
Common dialogs to allow the user to specify a file to open or save.
tkFont
Utilities to help work with fonts.
tkMessageBox
Access to standard Tk dialog boxes.
tkSimpleDialog
Basic dialogs and convenience functions.
Tkdnd
Drag-and-drop support for Tkinter.
turtle
Turtle graphics in a Tk window.
3. 名字更换对比
Tkinter -->tkinter
ScrolledText -->tkinter.scrolledtext
tkColorChooser -->tkinter.colorchooser
tkCommonDialog -->tkinter.commondialog
tkSimpleDialog -->tkinter.simpledialog
tkFont -->tkinter.font
tkMessageBox -->tkinter.messagebox
tkSimpleDialog -->tkinter.simpledialog
Tkdnd -->tkinter.dnd
turtle -->turtle
4.为什么要更换命名
在Python3.x版本中原先的那些Tk支持库,作为tkinter的子模块了,名字自然也就变了。
参考
https://docs.python.org/3.4/library/tkinter.html#tkinter-modules
https://docs.python.org/2.7/library/tkinter.html#tkinter-modules
网友评论