Search code examples
pythonwindowspywin32

MessageBox case for Ok an Cancel?


how can I make "cases" for the following code:

win32api.MessageBox(None,
                    "This Program Will do THIS:\n"
                    "blablabla",
                    "programtitler",
                    win32con.MB_OKCANCEL | win32con.MB_ICONQUESTION)

for example

if select ok, do THIS, if select cancel, do THAT.


Solution

  • Should be something like this. (C#)

        int result = win32api.MessageBox(None,
                            "This Program Will do THIS:\n"
                            "blablabla",
                            "programtitler",
                            win32con.MB_OKCANCEL | win32con.MB_ICONQUESTION)
    
        switch (result)
        {
            case win32con.MB_IDOK: 
            //OK Selected.
            //put 'ok' code here.
            break;
            case win32con.MB_IDCANCEL:
            //Cancel Selected.
            //put 'Cancel' code here.
            break;
        }
    

    Not versed in python, but you should be able to just use if statements instead of a switch, like so:

        if result == win32con.MB_IDOK:
            //put 'ok' code here
        elif result == win32con.MB_IDCANCEL:
            //put 'cancel' code here