在脚本中进入可视化设计界面
ANSA提供了友好的GUI设计界面:
学习初期使用起来较方便,GUI设计熟练后直接用代码更好
import ansa
from ansa import guitk
from ansa import constants
def add_function_name():
TopWindow = guitk.BCWindowCreate("Liauto", guitk.constants.BCOnExitDestroy)
guitk.BCShow(TopWindow)
add_function_name()
guitk.BCAddToolTip(w, tip)guitk.BCAddToolTip(TopWindow, "xxx")guitk.BCSetBackgroundColor(TopWindow, 100, 100, 100)guitk.BCSetForegroundColor(TopWindow, 100, 100, 100)
与Office的PPT、 \LaTeX的Beamer类似,先建立画布,再在画布上建立内容。
guitk.BCFrameCreateguitk.BCFrameCreate(p)p:父(parent,上级)widget或layoutBCFrame_1 = guitk.BCFrameCreate(TopWindow)Frame后,一般会自动建立一个BoxLayout
guitk.BCBoxLayoutCreateguitk.BCBoxLayoutCreate(p, o)p:父(parent,上级)widget或layouto:内部的排列方向
(orientation),可选择guitk.constants.BCHorizontal或guitk.constants.BCVerticalBCBoxLayout_1 = guitk.BCBoxLayoutCreate(BCFrame_1, guitk.constants.BCVertical)guitk.BCButtonGroupCreateguitk.BCButtonGroupCreate(p, title, o)title:ButtonGroup的标题(名称)BCButtonGroup_1 = guitk.BCButtonGroupCreate(BCBoxLayout_1, "BCButtonGroup_1", guitk.constants.BCVertical)
HBox调用格式:guitk.BCHBoxCreate(p)p中创建一个内部组件横排的方框。VBox调用格式:guitk.BCVBoxCreate(p)p中创建一个内部组件竖排的方框。
网格分布:
guitk.BCGridLayoutCreateguitk.BCGridLayoutCreate(p, numRows, numCols) 实例:import ansa
from ansa import guitk
from ansa import constants
def add_function_name():
TopWindow = guitk.BCWindowCreate("Liauto", guitk.constants.BCOnExitDestroy)
BCFrame_1 = guitk.BCFrameCreate(TopWindow)
BCBoxLayout_1 = guitk.BCBoxLayoutCreate(BCFrame_1, guitk.constants.BCVertical)
BCButtonGroup_1 = guitk.BCButtonGroupCreate(BCBoxLayout_1, "BCButtonGroup_1", guitk.constants.BCVertical)
BCButtonGroup_2 = guitk.BCButtonGroupCreate(BCBoxLayout_1, "BCButtonGroup_2", guitk.constants.BCVertical)
BCGridLayout_1 = guitk.BCGridLayoutCreate(BCButtonGroup_2, 2, 2)
BCPushButton_1 = guitk.BCPushButtonCreate(BCGridLayout_1, "BCPushButton_1", None, None)
guitk.BCGridLayoutAddWidget(BCGridLayout_1, BCPushButton_1, 0, 0, guitk.constants.BCAlignVCenter + guitk.constants.BCAlignLeft)
BCPushButton_2 = guitk.BCPushButtonCreate(BCGridLayout_1, "BCPushButton_2", None, None)
guitk.BCGridLayoutAddWidget(BCGridLayout_1, BCPushButton_2, 0, 1, guitk.constants.BCAlignVCenter + guitk.constants.BCAlignLeft)
BCPushButton_3 = guitk.BCPushButtonCreate(BCGridLayout_1, "BCPushButton_3", None, None)
guitk.BCGridLayoutAddWidget(BCGridLayout_1, BCPushButton_3, 1, 0, guitk.constants.BCAlignVCenter + guitk.constants.BCAlignLeft)
BCPushButton_4 = guitk.BCPushButtonCreate(BCGridLayout_1, "BCPushButton_4", None, None)
guitk.BCGridLayoutAddWidget(BCGridLayout_1, BCPushButton_4, 1, 1, guitk.constants.BCAlignVCenter + guitk.constants.BCAlignLeft)
guitk.BCShow(TopWindow)
add_function_name()
当内容很多时,可以通过Toolbox对frame进行折叠,类比于将文件放进文件夹,点击才会打开
BCToolBoxCreateguitk.BCToolBoxCreate(p)