# How do I make a pop up dialog that goes away when pressed “ok”?

I made the code below. It does exactly what I want except that the pop up dialog does not go away after pressing "ok" button on the pop up. Basically I want a pop up dialog where the user enters a name for the scene save. I trimmed the code to make it concise here.

Everything seems to work except that after I put a name in the field and press "ok", the dialog still stays there, instead I want it to go away after pressing "ok"

class MYOP(bpy.types.Operator):
bl_idname = "wm.myop"
bl_label = "Scene Save"

name = StringProperty(name="Name", default="")

def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)

def execute(self,context):
bpy.ops.wm.myop('INVOKE_DEFAULT')
savescene(context, self.name)

return {'FINISHED'}


class FILE_MT_SceneSave(bpy.types.Menu):
bl_label = "SceneSave"
bl_idname = "FILE_MT_scenesave"

def draw(self, context):
layout = self.layout

scn=context.scene
wm = context.window_manager
layout.operator("wm.myop",text="Save")


I am targeting Blender 2.80.

When you press "Ok" you are calling the execute method of the operator, in which you are re-calling your operator. Get rid of bpy.ops.wm.myop('INVOKE_DEFAULT') in the execute method.

Blender 2.8 uses annotations for properties.

Blender 2.8 uses strict naming conventions for operator and panel class names. For the operator with id wm.myop the class needs to be named WM_OT_myop. Please check the system console for errors.

import bpy

class WM_OT_myop(bpy.types.Operator):
"""Tooltip"""
bl_idname = "wm.myop"
bl_label = "Simple Object Operator"
# annotations in 2.8
name : bpy.props.StringProperty(name="Name", default="")

@classmethod
def poll(cls, context):
return context.active_object is not None

def execute(self, context):
return {'FINISHED'}

def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)

self.layout.operator("wm.myop")

def register():
bpy.utils.register_class(WM_OT_myop)

def unregister():
bpy.utils.unregister_class(WM_OT_myop)

if __name__ == "__main__":
register()

# test call
bpy.ops.wm.myop('INVOKE_DEFAULT')


In order to make the operator work as part of a 'floating menu' you have to set the operator_context property of the layout beforehand, which basically allows to display the popup:

import bpy

class WM_OT_myop(bpy.types.Operator):
"""Tooltip"""
bl_idname = "wm.myop"
bl_label = "Simple Object Operator"

name: bpy.props.StringProperty(name="Name", default="")

@classmethod
def poll(cls, context):
return context.active_object is not None

def execute(self, context):
return {'FINISHED'}

def invoke(self, context, event):
wm = context.window_manager
return wm.invoke_props_dialog(self)

def draw(self, context):
layout = self.layout
layout.operator("wm.save_as_mainfile").copy = True

layout.operator_context = 'INVOKE_DEFAULT'
layout.operator("wm.myop")

def register():
bpy.utils.register_class(WM_OT_myop)

def unregister():
bpy.utils.unregister_class(WM_OT_myop)

if __name__ == "__main__":
register()

# The menu can also be called from scripts

• Thanks your code works, I get it but my issue is that I need to call this operator from a menu like layout.operator("wm.myop",text="Save") and that is my issue. You are able to call the op from the main with bpy.ops which naturally works and that is why I stuck that bpy.ops inside the operator itself. I hope it makes sense. Basically when I call from a menu via layout.operator I cant make it to trigger the pop up. – yarun can Feb 18 at 17:56