日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python彈框二之tkinter.messagebox

系統 2185 0

? ? ? ? 前面寫過python彈框的ctypes.windll.user32方法:https://blog.csdn.net/Gordennizaicunzai/article/details/78966694

該方法調用windows系統的user32組件,不是純python方法,且wser32的MessageBoxA使用不當會出現亂碼,不是很好用。這里介紹pythonic的彈框——tkinter.messagebox。

NAME
? ? tkinter.messagebox

DESCRIPTION
? ? # tk common message boxes
? ? #
? ? # this module provides an interface to the native message boxes
? ? # available in Tk 4.2 and newer.
? ? #
? ? # written by Fredrik Lundh, May 1997
? ? #

CLASSES
? ? tkinter.commondialog.Dialog(builtins.object)
? ? ? ? Message
? ??
? ? class Message(tkinter.commondialog.Dialog)
? ? ?| ?Message(master=None, **options)
? ? ?| ?
? ? ?| ?A message box
? ? ?| ?
? ? ?| ?Method resolution order:
? ? ?| ? ? ?Message
? ? ?| ? ? ?tkinter.commondialog.Dialog
? ? ?| ? ? ?builtins.object
? ? ?| ?
? ? ?| ?Data and other attributes defined here:
? ? ?| ?
? ? ?| ?command = 'tk_messageBox'
? ? ?| ?
? ? ?| ?----------------------------------------------------------------------
? ? ?| ?Methods inherited from tkinter.commondialog.Dialog:
? ? ?| ?
? ? ?| ?__init__(self, master=None, **options)
? ? ?| ? ? ?Initialize self. ?See help(type(self)) for accurate signature.
? ? ?| ?
? ? ?| ?show(self, **options)
? ? ?| ?
? ? ?| ?----------------------------------------------------------------------
? ? ?| ?Data descriptors inherited from tkinter.commondialog.Dialog:
? ? ?| ?
? ? ?| ?__dict__
? ? ?| ? ? ?dictionary for instance variables (if defined)
? ? ?| ?
? ? ?| ?__weakref__
? ? ?| ? ? ?list of weak references to the object (if defined)

FUNCTIONS

showinfo(title=None, message=None, **options)
? ? ? ? Show an info message

注意,tkinter.messagebox默認主窗口是顯示狀態,我們彈框時它是多于的,需要隱藏。

            
              >>> import tkinter as tk
>>> from tkinter import messagebox as messagebox
>>> 
>>> messagebox.showinfo('彈框', '注意,主窗口未退出')
'ok'
>>> 
            
          

python彈框二之tkinter.messagebox_第1張圖片 ? ?

隱藏主窗口,函數要放在彈框前,否則無效:

showerror(title=None, message=None, **options)
? ? ? ? Show an error message

            
              >>> tk.Tk().withdraw()  # 隱藏主窗口
''
>>> messagebox.showerror('彈框', 'say something')
'ok'
>>> 
            
          


? ?? python彈框二之tkinter.messagebox_第2張圖片

? ??
? ? showwarning(title=None, message=None, **options)
? ? ? ? Show a warning message

            
              >>> tk.Tk().deiconify()  # 顯示主窗口
''
>>> messagebox.showwarning('彈框', 'say something')
'ok'
>>> 
            
          

python彈框二之tkinter.messagebox_第3張圖片

askokcancel(title=None, message=None, **options)
? ? ? ? Ask if operation should proceed; return true if the answer is ok


? ? ? ? 選擇確定/取消,返回值分別對應true/false,下同:

            
              >>> 
>>> tk.Tk().withdraw()  # 隱藏主窗口
''
>>> msg = messagebox.askokcancel('對話框', '請選擇')
>>> msg
False
>>> 
            
          

python彈框二之tkinter.messagebox_第4張圖片
? ? askquestion(title=None, message=None, **options)
? ? ? ? Ask a question

            
              >>> 
>>> msg = messagebox.askquestion('對話框', '請選擇')
>>> 
            
          

python彈框二之tkinter.messagebox_第5張圖片
? ??
? ? askretrycancel(title=None, message=None, **options)
? ? ? ? Ask if operation should be retried; return true if the answer is yes

            
              msg = messagebox.askretrycancel('對話框', '請選擇')
            
          


? ?? python彈框二之tkinter.messagebox_第6張圖片
? ? askyesno(title=None, message=None, **options)
? ? ? ? Ask a question; return true if the answer is yes
? ??

            
               msg = messagebox.askyesno('對話框', '請選擇')
            
          

python彈框二之tkinter.messagebox_第7張圖片
? ? askyesnocancel(title=None, message=None, **options)
? ? ? ? Ask a question; return true if the answer is yes, None if cancelled.

            
              >>> msg = messagebox.askyesnocancel('對話框', '請選擇')
>>> msg
True
>>> msg = messagebox.askyesnocancel('對話框', '請選擇')
>>> msg
False
>>> msg = messagebox.askyesnocancel('對話框', '請選擇')
>>> msg
>>> 
            
          


? ?? python彈框二之tkinter.messagebox_第8張圖片

DATA
? ? ABORT = 'abort'
? ? ABORTRETRYIGNORE = 'abortretryignore'
? ? CANCEL = 'cancel'
? ? ERROR = 'error'
? ? IGNORE = 'ignore'
? ? INFO = 'info'
? ? NO = 'no'
? ? OK = 'ok'
? ? OKCANCEL = 'okcancel'
? ? QUESTION = 'question'
? ? RETRY = 'retry'
? ? RETRYCANCEL = 'retrycancel'
? ? WARNING = 'warning'
? ? YES = 'yes'
? ? YESNO = 'yesno'
? ? YESNOCANCEL = 'yesnocancel'


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 那坡县| 广宗县| 衡南县| 赣榆县| 攀枝花市| 阜平县| 广安市| 光泽县| 来安县| 鄂伦春自治旗| 南宫市| 长武县| 武威市| 宁德市| 灵璧县| 漯河市| 津南区| 新泰市| 手游| 东辽县| 宜章县| 扎赉特旗| 北海市| 丰台区| 荃湾区| 含山县| 昆山市| 武平县| 东宁县| 商河县| 赤壁市| 湖南省| 衢州市| 卢湾区| 柳河县| 万全县| 云安县| 高安市| 饶阳县| 普安县| 沙河市|