1. 遇到的問題
在學習Python的標準庫tkinter的時候掩浙,教程用的是Python2.7 , 而我使用的是的Python3.4施绎。按照教程加載tkMessageBox庫享郊,發(fā)現(xiàn)居然沒有這個庫。猜想應該是把tkMessageBox的名字給換成別的了靡努。
2. 問題的解決
上Python官網(wǎng)去查看想是否有相關信息。找到了以下信息晓折,就猜測的那樣是把命名給換了惑朦。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