MotionBuilder Python Script18 - UI_Label

The Night Knight

今天学习了一部分导入流程,写完这篇就整理整理

今天我们来看一下UI中最常用的控件 Label

一、Label

标签,可以用于显示文本和图片

我们先来看一下UI效果

UI效果

这里展示了多种Label的显示形式,之后我会再研究一下能否用于显示图片(当然可以直接用ImageContainer

来看一下代码

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Create a tool with labels and set all their properties.
#
# Topic: FBLabel, FBTextJustify, FBTextStyle
#

from pyfbsdk import *
from pyfbsdk_additions import *


def PopulateLayout(mainLyt):
    lyt = FBVBoxLayout()
    x = FBAddRegionParam(0, FBAttachType.kFBAttachLeft, "")
    y = FBAddRegionParam(0, FBAttachType.kFBAttachTop, "")
    w = FBAddRegionParam(50, FBAttachType.kFBAttachNone, "")
    h = FBAddRegionParam(0, FBAttachType.kFBAttachBottom, "")
    mainLyt.AddRegion("main", "main", x, y, w, h)
    mainLyt.SetControl("main", lyt);

    l = FBLabel()
    l.Caption = "This is a label!!!!"
    l.Style = FBTextStyle.kFBTextStyleBold
    l.WordWrap = True
    lyt.Add(l, 25)

    # FBTextJustify.kFBTextJustifyLeft
    # FBTextJustify.kFBTextJustifyRight
    # FBTextJustify.kFBTextJustifyCenter

    # FBTextStyle.kFBTextStyleNone
    # FBTextStyle.kFBTextStyleBold
    # FBTextStyle.kFBTextStyleItalic
    # FBTextStyle.kFBTextStyleUnderlined

    l = FBLabel()
    l.Caption = "left"
    l.Style = FBTextStyle.kFBTextStyleItalic
    l.Justify = FBTextJustify.kFBTextJustifyLeft
    lyt.Add(l, 25)

    l = FBLabel()
    l.Caption = "center"
    l.Style = FBTextStyle.kFBTextStyleUnderlined
    l.Justify = FBTextJustify.kFBTextJustifyCenter
    lyt.Add(l, 25)

    l = FBLabel()
    l.Caption = "right"
    l.Justify = FBTextJustify.kFBTextJustifyRight
    lyt.Add(l, 25)


def CreateTool():
    # Tool creation will serve as the hub for all other controls
    t = FBCreateUniqueTool("Label Example")
    t.StartSizeX = 400
    t.StartSizeY = 400
    PopulateLayout(t)
    ShowTool(t)


CreateTool()

代码清晰,decomposition and refactor!

二、结语

有什么问题可以留言

继续!

共勉!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容