Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解

作者:随风行云 时间:2022-10-26 19:49:05 

本文实例讲述了Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法。分享给大家供大家参考,具体如下:

相关内容:

  • messagebox

    • 介绍

    • 使用

  • filedialog

    • 介绍

    • 使用

首发时间:2018-03-04 22:18


messagebox:

  • 介绍:messagebox是tkinter中的消息框、对话框

  • 使用:

    • 提示消息框:【返回”ok”】Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解

      tkinter.messagebox.showinfo(消息框标题,提示内容)      

    • 消息警告框【返回”ok”】:Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解

      tkinter.messagebox.showwarning(消息框标题,警告内容)      

    • 错误消息框【返回”ok”】:Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解

      tkinter.messagebox.showerror(消息框标题,错误提示内容)      

    • 对话框:

    • 询问确认对话框[返回”yes”,”no”]:Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解        

      tkinter.messagebox.askquestion(消息框标题,提示内容)        

    • 确认/取消对话框[返回True False]:Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解        

      tkinter.messagebox.askokcancel(消息框标题,提示内容)        

    •        

      是/否对话框【返回True False】:Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解

      tkinter.messagebox.askyesno(消息框标题,提示内容)        

    • 重试/取消对话框:【返回值:True False】Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解

      tkinter.messagebox.askretrycancel(标题,提示内容)        

    • 是\否\取消对话框: 【返回值:是:True  否:False 取消:None】:        

      tkinter.messagebox.askyesnocancel(标题,提示内容)        

      from tkinter import *import tkinter.messageboxdef info_warn_err():  a=tkinter.messagebox.showinfo("我的标题","我的提示1")  print(a)  a=tkinter.messagebox.showwarning("我的标题","我的提示2")  print(a)  a=tkinter.messagebox.showerror("我的标题", "我的提示3")  print(a)def func2():  a=tkinter.messagebox.askyesno("我的标题","我的提示1")  print(a)  a=tkinter.messagebox.askokcancel("我的标题","我的提示2")  print(a)  a=tkinter.messagebox.askquestion("我的标题","我的提示3")  print(a)  a=tkinter.messagebox.askretrycancel("我的标题","我的提示4")  print(a)  a=tkinter.messagebox.askyesnocancel("我的标题","我的提示5")  print(a)  #这里用作演示如何使用对话框  if tkinter.messagebox.askyesno("我的标题", "确认关闭窗口吗!"):    root.destroy()root=Tk()btn=Button(root,text="信息、警告、错误消息框",command=info_warn_err)btn1=Button(root,text="对话框",command=func2)btn.pack()btn1.pack()root.mainloop()        


      filedialog:

      import tkinter.filedialogfrom tkinter import *def func1():  a=tkinter.filedialog.asksaveasfilename()#返回文件名  print(a)  a =tkinter.filedialog.asksaveasfile()#会创建文件  print(a)  a =tkinter.filedialog.askopenfilename()#返回文件名  print(a)  a =tkinter.filedialog.askopenfile()#返回文件流对象  print(a)  a =tkinter.filedialog.askdirectory()#返回目录名  print(a)  a =tkinter.filedialog.askopenfilenames()#可以返回多个文件名  print(a)  a =tkinter.filedialog.askopenfiles()#多个文件流对象  print(a)root=Tk()btn1=Button(root,text="click",command=func1)btn1.pack()root.mainloop()        

    • 导入模块:import tkinter.filedialog

    • 选择文件对话框的格式:

    • tkinter.filedialog.asksaveasfilename():选择以什么文件名保存,返回文件名

    • tkinter.filedialog.asksaveasfile():选择以什么文件保存,创建文件并返回文件流对象

    • tkinter.filedialog.askopenfilename():选择打开什么文件,返回文件名

    • tkinter.filedialog.askopenfile():选择打开什么文件,返回IO流对象

    • tkinter.filedialog.askdirectory():选择目录,返回目录名

    • tkinter.filedialog.askopenfilenames():选择打开多个文件,以元组形式返回多个文件名

    • tkinter.filedialog.askopenfiles():选择打开多个文件,以列表形式返回多个IO流对象

    • 介绍:filedialog是tkinter中的文件对话框Python GUI编程学习笔记之tkinter中messagebox、filedialog控件用法详解

    • 使用:

    • 导入模块:import tkinter.messagebox

    • 选择消息框的模式:

    希望本文所述对大家Python程序设计有所帮助。

    来源:https://www.cnblogs.com/progor/p/8506513.html

    标签:Python,GUI编程,tkinter
    0
    投稿

    猜你喜欢

  • SQL语句操作主从关系表

    2011-06-19 13:19:05
  • js 中以 ... 为前缀的几种用法详解

    2024-04-18 09:40:38
  • python DataFrame中loc与iloc取数据的基本方法实例

    2022-06-23 15:58:25
  • Vue2.0/3.0双向数据绑定的实现原理详解

    2024-05-21 10:17:58
  • 使用Pycharm创建一个Django项目的超详细图文教程

    2021-07-13 10:47:17
  • JS获取当前时间的年月日时分秒及时间的格式化的方法

    2024-04-17 10:23:00
  • python读取json文件并将数据插入到mongodb的方法

    2021-03-22 20:30:22
  • python中 OpenCV和Pillow处理图像操作及时间对比

    2021-02-04 16:46:52
  • asp如何使用ADO 2x Command 对象读取数据?

    2010-06-03 10:51:00
  • PL/SQL数据类型及操作符

    2009-02-26 11:17:00
  • python中时间、日期、时间戳的转换的实现方法

    2022-03-20 13:37:12
  • SQL Server连接中三个常见的错误分析

    2024-01-14 21:30:23
  • python数学建模之Numpy 应用介绍与Pandas学习

    2022-09-13 07:39:32
  • php函数重载的替代方法--伪重载详解

    2023-11-18 10:24:06
  • Flask 入门系列 Cookie与session的介绍

    2022-06-21 00:45:44
  • matplotlib阶梯图的实现(step())

    2023-03-18 23:29:54
  • 图标设计常犯的10种错误

    2008-03-06 13:40:00
  • 使用Django和Postgres进行全文搜索的实例代码

    2022-07-06 10:52:15
  • 详解Python3 pandas.merge用法

    2023-07-04 20:26:48
  • Sql Server中的非聚集索引详细介

    2024-01-26 15:57:56
  • asp之家 网络编程 m.aspxhome.com