今天初次使用Python Tkinter來作了個簡單的記事本程序。發現Python2.x和Python3.x的Tkinter模塊的好多內置函數都有所改變,這裏簡單整理一下以備往後查驗。函數
Python2.x:post
from Tkinter import *code
Python3.x:blog
from tkinter import *it
Python2.X:import
import tkFileDialog亂碼
filename = tkFileDialog.askopenfilename(filetypes=[("bmp格式".decode('gbk'),"bmp")])List
#注意:Python2.X會有中文亂碼問題,須要在"中文"後加.decode('gbk') 。Python3.X則不須要file
這裏能夠加入屬性: initialdir 設置默認初始路徑。即:程序
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()