How can I create a simple message box in Python?
--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Book End
--
Chapters
00:00 How Can I Create A Simple Message Box In Python?
00:41 Answer 1 Score 64
00:51 Answer 2 Score 23
01:08 Answer 3 Score 24
01:29 Accepted Answer Score 376
02:01 Thank you
--
Full question
https://stackoverflow.com/questions/2963...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #wxpython #tkinter
#avk47
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Book End
--
Chapters
00:00 How Can I Create A Simple Message Box In Python?
00:41 Answer 1 Score 64
00:51 Answer 2 Score 23
01:08 Answer 3 Score 24
01:29 Accepted Answer Score 376
02:01 Thank you
--
Full question
https://stackoverflow.com/questions/2963...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #wxpython #tkinter
#avk47
ACCEPTED ANSWER
Score 376
You could use an import and single line code like this:
import ctypes # An included library with Python install.
ctypes.windll.user32.MessageBoxW(0, "Your text", "Your title", 1)
Or define a function (Mbox) like so:
import ctypes # An included library with Python install.
def Mbox(title, text, style):
return ctypes.windll.user32.MessageBoxW(0, text, title, style)
Mbox('Your title', 'Your text', 1)
Note the styles are as follows:
## Styles:
## 0 : OK
## 1 : OK | Cancel
## 2 : Abort | Retry | Ignore
## 3 : Yes | No | Cancel
## 4 : Yes | No
## 5 : Retry | Cancel
## 6 : Cancel | Try Again | Continue
Have fun!
Note: edited to use MessageBoxW instead of MessageBoxA
ANSWER 2
Score 64
Have you looked at easygui?
import easygui
easygui.msgbox("This is a message!", title="simple gui")
ANSWER 3
Score 24
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!")
ANSWER 4
Score 23
The code you presented is fine! You just need to explicitly create the "other window in the background" and hide it, with this code:
import Tkinter
window = Tkinter.Tk()
window.wm_withdraw()
Right before your messagebox.