2017-06-03 24 views
0

所以,我想輸入從對話框中存儲與​​庫:如何使用ctypes庫檢查Python中消息框按鈕的輸入?

import ctypes 
def mbox(message, title, style): 
    ctypes.windll.user32.MessageBoxW(message, title, style) 

mbox("This is a message box test", "Message Box", 1) 

的風格,當然,一個確定和取消按鈕。如何我從當你點擊一個按鈕,然後分割成一個單獨的功能什麼的,比如輸入:

if [Insert said check here]: 
    mbox("You pressed OK!", "Answer", 0) 
else: 
    mbox("You pressed Cancel!", "Answer", 0) 
+0

你需要捕捉消息框的返回值,並從'mbox' – abccd

回答

0

提供風格MB_OKCANCELMessageBox並測試其返回值。您可以在MessageBox function

import ctypes 
class MbConstants: 
    MB_OKCANCEL = 1 
    IDCANCEL = 2 
    IDOK = 1 

def mbox(message, title): 
    return ctypes.windll.user32.MessageBoxW(0,message, title, MbConstants.MB_OKCANCEL) 

rc = mbox("message","title") 
if rc == MbConstants.IDOK: 
    print("ok") 
elif rc == MbConstants.IDCANCEL: 
    print("cancel") 
+0

不要混淆與提示消息... MassageBoxes他們只是按摩的人,而不是返回它找到的數值顯示對話框。另外,你如何以不同的風格執行相同的動作,你是否會使用'IDABORT'或'IDRETRY'等東西? –

+0

是的。返回值是按下的按鈕的ID。 – napuzba