The following code demonstrates a simple “Hello World” message box.
After pressing the OK button, we can check the return value of the message box function.
We notice that the window size for the message box is too small to display the full title in the title bar, and unfortunately message boxes are not resizable by default (whereas tktoplevel windows are resizable by default). A simple way to fix this (which is admittedly not very elegant), is to add spaces on the end of the message to make it at least as long as the title.
Of course, sometimes it is desirable to have other buttons and/or other icons in a message box. The following examples illustrate some typical choices of buttons and icons.