zoukankan      html  css  js  c++  java
  • python tkinter-消息框、对话框、文件对话框

    python tkinter-消息框、对话框、文件对话框

     

    消息框 

    导入

    import tkinter
    import tkinter.messagebox #这个是消息框,对话框的关键

    提示消息框

    tkinter.messagebox.showinfo('提示','人生苦短')

    消息警告框

    tkinter.messagebox.showwarning('警告','明日有大雨')

    错误消息框

    tkinter.messagebox.showerror('错误','出错了')

    复制代码
    import tkinter
    import tkinter.messagebox
    def but():
        tkinter.messagebox.showinfo('提示', '人生苦短')
        #tkinter.messagebox.showwarning('警告', '明日有大雨')
        #tkinter.messagebox.showerror('错误', '出错了')
    root=tkinter.Tk()
    root.title('GUI')#标题
    root.geometry('800x600')#窗体大小
    root.resizable(False, False)#固定窗体
    tkinter.Button(root, text='hello button',command=but).pack()
    root.mainloop()
    复制代码

     对话框

     同样需要导入 tkinter.messagebox

    复制代码
    import tkinter
    import tkinter.messagebox
    def but():
        a=tkinter.messagebox.askokcancel('提示', '要执行此操作吗')
        print (a)
    root=tkinter.Tk()
    root.title('GUI')#标题
    root.geometry('800x600')#窗体大小
    root.resizable(False, False)#固定窗体
    tkinter.Button(root, text='hello button',command=but).pack()
    root.mainloop()
    复制代码

    点击

    确定返回 Ture 

    取消返回 False

    messagebox.askquestion

    a=tkinter.messagebox.askquestion('提示', '要执行此操作吗')

    返回 yes 和 no

    messagebox.askyesno

    a=tkinter.messagebox.askyesno('提示', '要执行此操作吗')

    返回 Ture 和 False

    messagebox.askretrycancel

    a=tkinter.messagebox.askretrycancel('提示', '要执行此操作吗')

    返回 Ture 和 False

    a=tkinter.messagebox.askyesnocancel('提示', '要执行此操作吗')

    这个有三个按钮

    是:True
    否:False
    取消:None

    filedialog  文件对话框

    用来获取文件路径和文件名

    import tkinter.filedialog
    a=tkinter.filedialog.askopenfilename()

    输出a得到文件路径和名字
    E:/1.txt
  • 相关阅读:
    9 与python2交互
    8 内置函数(未完成)
    7 事务
    [转]jquery.vTicker(垂直滚动)
    2015年工作总结(2016-02-02)
    jQuery plugin : jqTransform
    JQuery知识总结
    JQuery事件处理的注意事项
    JQuery基本选择器
    [二]JQueryMobile常用的组件介绍
  • 原文地址:https://www.cnblogs.com/it-tsz/p/10582493.html
Copyright © 2011-2022 走看看