• Tkinter 之MessageBox弹出框


    一、参数说明

    语法作用截图
    tk.messagebox.showwarning(title='提示', message='你确定要删除吗?') 警告信息弹窗  
    tk.messagebox.showinfo('提示','你确定要删除吗?') 提示信息弹窗  

     

    tk.messagebox.showerror('提示','你确定要删除吗?') 错误信息弹窗

    语法返回值作用
    tk.messagebox.askokcancel('提示','要执行此操作吗') True | False (疑问)确定取消对话框
    tk.messagebox.askquestion('提示', '要执行此操作吗') yes | no (疑问)是否对话框
    tk.messagebox.askyesno('提示', '要执行此操作吗') True | False (疑问)是否对话框
    tk.messagebox.askretrycancel('提示', '要执行此操作吗') True | False (警告)重试取消对话框
    语法返回值作用
    tk.filedialog.asksaveasfilename() 含后缀文件目录 另存为窗口弹窗。
    tk.filedialog.asksaveasfile() 文件流对象 另存为窗口弹窗,会创建文件。
    tkinter.filedialog.askopenfilename() 含后缀文件目录 打开文件弹窗。
    tk.filedialog.askopenfile() 文件流对象 打开文件弹窗,
    tk.filedialog.askdirectory() 目录名 选择文件弹窗
    tk.filedialog.askopenfilenames() 元组 打开多个文件名
    tk.filedialog.askopenfiles()# 列表 多个文件流对象

    二、代码示例

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    import tkinter as tk
    import tkinter.messagebox
    import tkinter.filedialog
     
    window = tk.Tk()
    # 设置窗口大小
    winWidth = 600
    winHeight = 400
    # 获取屏幕分辨率
    screenWidth = window.winfo_screenwidth()
    screenHeight = window.winfo_screenheight()
     
    x = int((screenWidth - winWidth) / 2)
    y = int((screenHeight - winHeight) / 2)
     
    # 设置主窗口标题
    window.title("MessageBox参数说明")
    # 设置窗口初始位置在屏幕居中
    window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
    # 设置窗口图标
    window.iconbitmap("./image/icon.ico")
    # 设置窗口宽高固定
    window.resizable(0, 0)
     
     
    tk.messagebox.askokcancel("提示", "你确定要删除吗?")
     
    tk.messagebox.askquestion("提示", "你确定要删除吗?")
     
    tk.messagebox.askyesno("提示", "你确定要删除吗?")
     
    tk.messagebox.askretrycancel("提示", "你确定要删除吗?")
     
     
    tk.messagebox.showinfo("提示", "你确定要删除吗?")
    tk.messagebox.showwarning("提示", "你确定要删除吗?")
    tk.messagebox.showerror("提示", "你确定要删除吗?")
     
    # tk.filedialog.asksaveasfilename()
     
     
    window.mainloop()

     

  • 相关阅读:
    最小树形图 朱刘算法模板+建边技巧
    模板倍增LCA 求树上两点距离 hdu2586
    【瞎搞题】gym226123 L. For the Honest Election
    【凸包板题】Gym
    集合3
    集合2
    集合1
    常用API&异常
    内部类&API
    多态&接口类&接口
  • 原文地址:https://www.cnblogs.com/wwqzb/p/12775501.html
Copyright © 2020-2023  润新知