tkinter的用法:tkinter用法 <https://docs.python.org/3/library/tkinter.html>

Python Tkinter Grid布局管理器详解:Python Tkinter Grid布局管理器详解
<https://blog.csdn.net/wangyiyan315/article/details/16821381>

Python3 tkinter系列:Python3 tkinter系列
<https://www.cnblogs.com/muziyunxuan/p/8268179.html>



一.导入方式:

  Python2.x:

    from Tkinter import *

  Python3.x:

    from tkinter import *



二.打开文件框:

  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")])



三.对话框:

  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()


友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:[email protected]
QQ群:637538335
关注微信