How can I create a simple message box in Python?

后端 未结 17 1330
心在旅途
心在旅途 2020-11-30 16:44

I\'m looking for the same effect as alert() in JavaScript.

I wrote a simple web-based interpreter this afternoon using Twisted.web. You basically submit

17条回答
  •  独厮守ぢ
    2020-11-30 17:49

    ctype module with threading

    i was using the tkinter messagebox but it would crash my code. i didn't want to find out why so i used the ctypes module instead.

    for example:

    import ctypes
    ctypes.windll.user32.MessageBoxW(0, "Your text", "Your title", 1)
    

    i got that code from Arkelis


    i liked that it didn't crash the code so i worked on it and added a threading so the code after would run.

    example for my code

    import ctypes
    import threading
    
    
    def MessageboxThread(buttonstyle, title, text, icon):
        threading.Thread(
            target=lambda: ctypes.windll.user32.MessageBoxW(buttonstyle, text, title, icon)
        ).start()
    
    messagebox(0, "Your title", "Your text", 1)
    

    for button styles and icon numbers:

    ## Button styles:
    # 0 : OK
    # 1 : OK | Cancel
    # 2 : Abort | Retry | Ignore
    # 3 : Yes | No | Cancel
    # 4 : Yes | No
    # 5 : Retry | No
    # 6 : Cancel | Try Again | Continue
    
    ## To also change icon, add these values to previous number
    # 16 Stop-sign icon
    # 32 Question-mark icon
    # 48 Exclamation-point icon
    # 64 Information-sign icon consisting of an 'i' in a circle
    

提交回复
热议问题