Python2.X和Python3.X文件对话框、下拉列表的不一样

Python2.X和Python3.X文件对话框、下拉列表的不一样  

今天初次使用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()

相关文章
相关标签/搜索