8

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

andio
  • 2,094
  • 6
  • 34
  • 70

1 Answers1

37

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:

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.

self.layout.label(text=message)
Gorgious
  • 30,723
  • 2
  • 44
  • 101
Skylumz
  • 586
  • 4
  • 10