今天初次使用Python Tkinter來作了個簡單的記事本程序。發現Python2.x和Python3.x的Tkinter模塊的好多內置函數都有所改變,這裏簡單整理一下以備往後查驗。函數
Python2.x:spa
from Tkinter import *code
Python3.x:it
from tkinter import *import
Python2.X:亂碼
import tkFileDialogList
filename = tkFileDialog.askopenfilename(filetypes=[("bmp格式".decode('gbk'),"bmp")])file
#注意:Python2.X會有中文亂碼問題,須要在"中文"後加.decode('gbk') 。Python3.X則不須要程序
這裏能夠加入屬性: initialdir 設置默認初始路徑。即:im
FileName = tkFileDialog.askopenfilename(filetypes=[("bmp格式".decode('gbk'),"bmp")], initialdir = 'E:')
Python3.X:
import tkinter.filedialog
filename=tkinter.filedialog.askopenfilename(filetypes=[("bmp格式","bmp")])
Python2.X:
import tkFileDialog
showinfo(title='中文標題'.decode('gbk'), message='XXX') #注意:中文要加.decode('gbk')
Python3.X:
import tkinter.messagebox
tkinter.messagebox.showinfo(title='XXX',message='XXX')
Python2.X:
import ttk
#注意:若是寫from ttk import * 會影響Label的屬性,這裏可能Label會自動調用ttk裏的Label?猜想而已
Python3.X:
from tkinter import ttk
用法同樣:
myComboList = ['AAA','BBB',]
myCombox = ttk.Combobox(root, values=myComboList )
myCombox .pack()