首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Blender -使用bpy插入文本按钮

Blender -使用bpy插入文本按钮
EN

Stack Overflow用户
提问于 2020-09-20 22:42:13
回答 1查看 209关注 0票数 0

我正在为Blender 2.80插件设计一个简单的GUI。我已经创建了一个对话框来输入一些数据:

我想替换文本行("Lorem ipsum ...")带有自定义标签的按钮(例如“单击此处访问我们的网站”)。

下面是我使用的代码:

代码语言:javascript
复制
class ExportFDSCloudHPC(Operator):

    bl_idname = "..."
    bl_label = "Title"
    bl_description = "..."

    data1 = bpy.props.StringProperty(
        name = "Text 1",
        default = "..."
    )

    data2 = bpy.props.StringProperty(
        name = "Text 2",
        default = "..."
    )

    data3 = bpy.props.StringProperty(
        name = "Text 3",
        default = "..."
    )
    
    def draw(self, context):
        col = self.layout.column(align = True)
        col.prop(self, "data1")

        self.layout.label(text="Lorem ipsum dolor sit amet, consectetur adipisci elit...")

        col = self.layout.column(align = True)
        col.prop(self, "data2")

        col = self.layout.column(align = True)
        col.prop(self, "data3")

    def execute(self, context):
        ...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-21 16:58:34

要获取按钮,您需要提供一个现有的操作符:row.operator("wm.save_as_mainfile")按钮文本在operator中定义。如果要更改现有操作员名称,请使用row.operator("wm.save_as_mainfile", text='My Save Label')

您可以创建自己的运算符:

代码语言:javascript
复制
import bpy

def main(context):
    for ob in context.scene.objects:
        print(ob)

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator" # <- put this string in layout.operator()
    bl_label = "Simple Object Operator" # <- button name

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

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

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

def unregister():
    bpy.utils.unregister_class(SimpleOperator)
    
if __name__ == "__main__":
    register()

    # test call
    bpy.ops.object.simple_operator()

然后像这样使用它:

代码语言:javascript
复制
[..]
col.prop(self, "data1")
col.operator("object.simple_operator")
# self.layout.label(text="Lorem ipsum dolor sit amet, consectetur adipisci elit...")

col = self.layout.column(align = True)
[..]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63980151

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档