Python2.X和Python3.X文件对话框、下拉列表的不同
来源:互联网 发布:淘宝苹果耳机店推荐 编辑:程序博客网 时间:2024/05/16 08:24
之前写过一个文章是关于用Python Tkinter画界面的。里面的代码、用到的函数都是Python3.X版本下的。今天尝试了下Python2.X版本,发现好几个函数都不能用了。两个版本区别还是真大。
这里把用到的不同列举下来,方便以后查看。
1.打开文件框:
Python2.X:
import tkFileDialog
filename = tkFileDialog.askopenfilename(filetypes=[("bmp格式".decode('gbk'),"bmp")])#注意:Python2.X会有中文乱码问题,需要在"中文"后加.decode('gbk') 。Python3.X则不需要
这里可以加入属性: initialdir 设置默认初始路径。即:
FileName = tkFileDialog.askopenfilename(filetypes=[("bmp格式".decode('gbk'),"bmp")], initialdir = 'E:')
Python3.X:
import tkinter.filedialog
filename=tkinter.filedialog.askopenfilename(filetypes=[("bmp格式","bmp")])
2.对话框:
Python2.X:
import tkFileDialog
showinfo(title='中文标题'.decode('gbk'), message='XXX') #注意:中文要加.decode('gbk')
Python3.X:
import tkinter.messagebox
tkinter.messagebox.showinfo(title='XXX',message='XXX')
3.下拉列表:
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()
- Python2.X和Python3.X文件对话框、下拉列表的不同
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Python3.x和Python2.x的区别
- Nginx与Lua
- Memcache命令及参数用法
- HBase入门篇3
- 快捷方式总结
- 开发工程师人生之路
- Python2.X和Python3.X文件对话框、下拉列表的不同
- OMAP3730开发板uboot学习以及nfs网络启动根文件系统
- ssh整合开发步骤
- java 传入结果集,和一个Class,把结果集转化为List对象
- MDCC上看到的东西 for md
- 为什么String类是不可变的?
- 第一次尝试权限管理
- subtitile in DVB
- 通过注册表获取硬件信息