MotionBuilder Python Script18 - UI_Label

The Night Knight

今天學(xué)習(xí)了一部分導(dǎo)入流程,寫完這篇就整理整理

今天我們來看一下UI中最常用的控件 Label

一、Label

標(biāo)簽,可以用于顯示文本和圖片

我們先來看一下UI效果

UI效果

這里展示了多種Label的顯示形式,之后我會(huì)再研究一下能否用于顯示圖片(當(dāng)然可以直接用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!

二、結(jié)語

有什么問題可以留言

繼續(xù)!

共勉!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容