tk支持库Python2.7与Python3.4命名的改变

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容