溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

messagebox和filedialog控件怎么在Python 中使用

發布時間:2021-05-11 15:55:30 來源:億速云 閱讀:262 作者:Leah 欄目:開發技術

messagebox和filedialog控件怎么在Python 中使用?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。

python主要應用領域有哪些

1、云計算,典型應用OpenStack。2、WEB前端開發,眾多大型網站均為Python開發。3.人工智能應用,基于大數據分析和深度學習而發展出來的人工智能本質上已經無法離開python。4、系統運維工程項目,自動化運維的標配就是python+Django/flask。5、金融理財分析,量化交易,金融分析。6、大數據分析。


messagebox:

  • 介紹:messagebox是tkinter中的消息框、對話框

  • 使用:

    • 提示消息框:【返回”ok”】messagebox和filedialog控件怎么在Python 中使用

      tkinter.messagebox.showinfo(消息框標題,提示內容)

       

    • 消息警告框【返回”ok”】:messagebox和filedialog控件怎么在Python 中使用

      tkinter.messagebox.showwarning(消息框標題,警告內容)

       

    • 錯誤消息框【返回”ok”】:messagebox和filedialog控件怎么在Python 中使用

      tkinter.messagebox.showerror(消息框標題,錯誤提示內容)

       

    • 對話框:

    • 詢問確認對話框[返回”yes”,”no”]:messagebox和filedialog控件怎么在Python 中使用

      tkinter.messagebox.askquestion(消息框標題,提示內容)


    • 確認/取消對話框[返回True False]:messagebox和filedialog控件怎么在Python 中使用

      tkinter.messagebox.askokcancel(消息框標題,提示內容)


    • 是/否對話框【返回True False】:messagebox和filedialog控件怎么在Python 中使用

      tkinter.messagebox.askyesno(消息框標題,提示內容)


    • 重試/取消對話框:【返回值:True False】messagebox和filedialog控件怎么在Python 中使用

      tkinter.messagebox.askretrycancel(標題,提示內容)
    • 是\否\取消對話框: 【返回值:是:True  否:False 取消:None】:

      tkinter.messagebox.askyesnocancel(標題,提示內容)


      from tkinter import *
      import tkinter.messagebox
      def 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.filedialog
      from 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中的文件對話框messagebox和filedialog控件怎么在Python 中使用

    • 使用:

    • 導入模塊:import tkinter.messagebox

    • 選擇消息框的模式:

看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女