How can I create a simple message box in Python?

后端 未结 17 1319
心在旅途
心在旅途 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:31

    You can use pyautogui or pymsgbox:

    import pyautogui
    pyautogui.alert("This is a message box",title="Hello World")
    

    Using pymsgbox is the same as using pyautogui:

    import pymsgbox
    pymsgbox.alert("This is a message box",title="Hello World")
    
    0 讨论(0)
  • 2020-11-30 17:32
    import ctypes
    ctypes.windll.user32.MessageBoxW(0, "Your text", "Your title", 1)
    

    The last number (here 1) can be change to change window style (not only buttons!):

    ## 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
    

    For example,

    ctypes.windll.user32.MessageBoxW(0, "That's an error", "Warning!", 16)
    

    will give this:

    0 讨论(0)
  • 2020-11-30 17:36
    import sys
    from tkinter import *
    def mhello():
        pass
        return
    
    mGui = Tk()
    ment = StringVar()
    
    mGui.geometry('450x450+500+300')
    mGui.title('My youtube Tkinter')
    
    mlabel = Label(mGui,text ='my label').pack()
    
    mbutton = Button(mGui,text ='ok',command = mhello,fg = 'red',bg='blue').pack()
    
    mEntry = entry().pack 
    
    0 讨论(0)
  • 2020-11-30 17:36

    check out my python module: pip install quickgui (Requires wxPython, but requires no knowledge of wxPython) https://pypi.python.org/pypi/quickgui

    Can create any numbers of inputs,(ratio, checkbox, inputbox), auto arrange them on a single gui.

    0 讨论(0)
  • 2020-11-30 17:36

    A recent message box version is the prompt_box module. It has two packages: alert and message. Message gives you greater control over the box, but takes longer to type up.

    Example Alert code:

    import prompt_box
    
    prompt_box.alert('Hello') #This will output a dialog box with title Neutrino and the 
    #text you inputted. The buttons will be Yes, No and Cancel
    

    Example Message code:

    import prompt_box
    
    prompt_box.message('Hello', 'Neutrino', 'You pressed yes', 'You pressed no', 'You 
    pressed cancel') #The first two are text and title, and the other three are what is 
    #printed when you press a certain button
    
    0 讨论(0)
  • 2020-11-30 17:37

    Also you can position the other window before withdrawing it so that you position your message

    #!/usr/bin/env python
    
    from Tkinter import *
    import tkMessageBox
    
    window = Tk()
    window.wm_withdraw()
    
    #message at x:200,y:200
    window.geometry("1x1+200+200")#remember its .geometry("WidthxHeight(+or-)X(+or-)Y")
    tkMessageBox.showerror(title="error",message="Error Message",parent=window)
    
    #centre screen message
    window.geometry("1x1+"+str(window.winfo_screenwidth()/2)+"+"+str(window.winfo_screenheight()/2))
    tkMessageBox.showinfo(title="Greetings", message="Hello World!")
    
    0 讨论(0)
提交回复
热议问题