• 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()# 列表 多个文件流对象

    二、代码示例

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

      

  • 相关阅读:
    awk书上练习
    矩阵运算
    从最大似然到EM算法浅解
    numpy 练习
    python lxml教程
    pycharm快捷键
    python正则表达式教程
    三门问题
    Solr本地服务器搭建及查询
    git简单使用
  • 原文地址:https://www.cnblogs.com/yang-2018/p/11793001.html
Copyright © 2020-2023  润新知