How can i popup message box from python console ? something like message('test').

  • $\begingroup$ bpy.ops.wm.splash('INVOKE_DEFAULT') pops up the splash screen. On writing an operator with a dialogue see Related $\endgroup$ – batFINGER May 30 '18 at 13:24
  • 1
    $\begingroup$ there is no popup box in blender like you get with javascript alert("test") $\endgroup$ – David May 30 '18 at 13:34

One way to do this is by using a operator and the self.report() method. Here is a example

import bpy

class MessageBoxOperator(bpy.types.Operator):
    bl_idname = "ui.show_message_box"
    bl_label = "Minimal Operator"

    def execute(self, context):
        #this is where I send the message
        self.report({'INFO'}, "This is a test")
        return {'FINISHED'}


# test call to the 

This will show a little message box up in the top tool bar and really isn't efficient for a bigger/longer message.

Another more efficient way of displaying a message box is window_manager.popup_menu() here is an example script:

import bpy

def ShowMessageBox(message = "", title = "Message Box", icon = 'INFO'):

    def draw(self, context):

    bpy.context.window_manager.popup_menu(draw, title = title, icon = icon)

#Shows a message box with a specific message 
ShowMessageBox("This is a message") 

#Shows a message box with a message and custom title
ShowMessageBox("This is a message", "This is a custom title")

#Shows a message box with a message, custom title, and a specific icon
ShowMessageBox("This is a message", "This is a custom title", 'ERROR')

You can see hear I made a custom message box method called ShowMessageBox() this is what the method will show starting from the first example to the third:

ShowMessageBox() example 1

ShowMessageBox() example 2

ShowMessageBox() example 3

Hope this helps! (sorry for the super late reply)

EDIT for 2.80

UILayout.label(text="") requires text to be a keyword argument.

| improve this answer | |
  • $\begingroup$ The second method works but the first one , i can see any message box. where is it ? at top toolbar i can't see any message. $\endgroup$ – andio Jun 5 '18 at 19:56
  • $\begingroup$ How do I make this work under 2.8? $\endgroup$ – yarun can Jan 2 '19 at 7:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.