How can i popup message box from python console ? something like message('test').
1 Answer
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'}
bpy.utils.register_class(MessageBoxOperator)
# test call to the
bpy.ops.ui.show_message_box()
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):
self.layout.label(text=message)
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:
Hope this helps! (sorry for the super late reply)
EDIT for 2.80
UILayout.label(text="")
requires text
to be a keyword argument.
self.layout.label(text=message)
-
$\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$– andioJun 5, 2018 at 19:56
-
-
1$\begingroup$ @yaruncan I made it work by changing
self.layout.label(message)
toself.layout.label(text=message)
$\endgroup$– TangoMar 14, 2021 at 17:09
bpy.ops.wm.splash('INVOKE_DEFAULT')
pops up the splash screen. On writing an operator with a dialogue see Related $\endgroup$alert("test")
$\endgroup$