How to make a dialog box (three options like quit/OK/Cancel) in blender and processing the text entered through python or in C. I'm unable to find any good tutorial on this. Any help....?
Asked
Active
Viewed 2,796 times
3 Answers
1
A quick and dirty way is to use zenity command (should be included by default in any python distribution). Try this short example script, it works in my Blender 2.69 on Ubuntu 14.04.
import bpy # bpy or bge does not matter
import subprocess as SP
# call an OS subprocess $ zenity --entry --text "some text"
# (this will ask OS to open a window with the dialog)
res=SP.Popen(['zenity','--entry','--text',
'please write some text'], stdout=SP.PIPE)
# get the user input string back
usertext=str(res.communicate()[0][:-1])
# adjust user input string
text=usertext[2:-1]
print("I got this text from the user: %s"%text)
See the zenity --help for more complex dialogs

Mario Rossi
- 71
- 2
0
blender doesn't offer things like dialogs.
Answers to This previous question on external modules may be helpful.
-
class DialogOperator(bpy.types.Operator): bl_idname = "object.dialog_operator" bl_label = "Save Before You QUIT!" def execute(self, context): message = " You didn't saved yet " self.report({'INFO'}, message) print(message) return {'FINISHED'} def invoke(self, context, event): return context.window_manager.invoke_props_dialog(self) class DialogPanel(bpy.types.Panel): bl_label = "Dialog" bl_space_type = "VIEW_3D" bl_region_type = "UI" def draw(self, context): self.layout.operator("object.dialog_operator") – Oct 25 '13 at 04:47
-
This is the code I have generated for that dialog window but now I'm trying to Insert the yes no cancel options in that....I didn't found any useful answers till yet...If possible tell how to insert the buttons in the above code...thanks – Oct 25 '13 at 04:49
0
class DialogOperator(bpy.types.Operator)
bl_idname = "object.dialog_operator"
bl_label = "Save Before You QUIT!"
def execute(self, context):
message = " You didn't saved yet "
self.report({'INFO'}, message)
print(message)
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
class DialogPanel(bpy.types.Panel)
bl_label = "Dialog"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
def draw(self, context):
self.layout.operator("object.dialog_operator")
But this is only for creating a dialog window. after this have to insert buttons in this code.If anyone known this try to post the answer. At the same time I'm also trying to sort out this.

Richard Lalancette
- 2,401
- 24
- 29
-
In blender `bpy.types.Operator` is a class that performs actions, that is when you say delete this object the operator performs the task of deleting the object. `bpy.types.Panel` is a collapsible section within the side panes of a window or the properties window. While the DialogOperator shows a dialog like window it is meant as a method to alter values used by the operator, the ok button is automatically added and moving away from the dialog cancels it, these dialogs are normally shown by pressing F6 or shown at the bottom of the tools palette. – sambler Oct 25 '13 at 07:48
-
Class properties added below bl_label will be adjustable within the dialog and returned to the operator to use. Custom drawing is done through `def draw(self, context):` in the DialogOperator class. Buttons are normally shown in panels by adding an operator `row.operator("render.render")` not certain that will work in an operator dialog. – sambler Oct 25 '13 at 08:11
-
Thanks lot....def draw(self, context): row.operator("render.render") I tried...This not works ya... – Oct 25 '13 at 10:44