How can I create a simple message box in Python?

后端 未结 17 1383
心在旅途
心在旅途 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条回答
  •  旧时难觅i
    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!")
    

提交回复
热议问题