guitk.BCToolButtonCreateguitk.BCToolButtonCreate(p, iconname, label, funct, data)p:父(parent,上级)widget或layouticoname:按钮使用图标名称(一般在Windows Designer中选内部图标,也可以不填:"")label:按钮的名称、标签funct:按钮被按时执行的函数funct_name(b, data)b:对象,BCPushButton或BCToolButtondata:函数中需要的参数,从BCToolButtonCreate中输入data:输入进函数的参数,可以是anything(包括指针)BCToolButton_1 = guitk.BCToolButtonCreate(BCBoxLayout_1, "breakpoint_24.png", "Tool", None, 0)import ansa
from ansa import guitk
from ansa import constants
def main():
w = guitk.BCWindowCreate("Buttons", guitk.constants.BCOnExitDestroy)
#ToolButtons occupy only the space they need
tbut = guitk.BCToolButtonCreate(w, "file_open.svg", "Open", clickFunction, None)
#whereas PushButtons tend to occupy all available width
pbut = guitk.BCPushButtonCreate(w, "Open", clickFunction, None)
guitk.BCButtonSetIconFileName(pbut, "file_open.svg")
guitk.BCShow(w)
def clickFunction(b, data):
print("Button clicked")
return 0
main()
guitk.BCRadioButtonCreateguitk.BCRadioButtonCreate(p, label, funct, data)funct:选择该按钮时执行的函数;RadioButton都是好几个一起出现,所以会先定义ButtonGroup。因此函数一般不在这个地方单独定义,而是通过BCButtonGroupSetPressedFunction()来定义guitk.BCButtonGroupSetPressedFunctionguitk.BCButtonGroupSetPressedFunction(bg, funct, data)BCButtonGroupimport 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)
bgroup = guitk.BCButtonGroupCreate(BCBoxLayout_1, "Color Group", guitk.constants.BCVertical )
redRadioButton = guitk.BCRadioButtonCreate( bgroup, "Red", None, None )
greenRadioButton = guitk.BCRadioButtonCreate( bgroup, "Green", None, None )
blueRadioButton = guitk.BCRadioButtonCreate( bgroup, "Blue", None, None )
guitk.BCButtonGroupSetPressedFunction(bgroup, buttonGroupPressed, None)
guitk.BCShow(TopWindow)
def buttonGroupPressed(bg, index, data):
color_num = guitk.BCButtonGroupCount(bg)
if index == 0:
color_pick = "red"
elif index == 1:
color_pick = "green"
elif index == 2:
color_pick = "blue"
print("There are {} colors, you have selected {}.".format(color_num,color_pick))
add_function_name()
BCPushButtonCreateguitk.BCPushButtonCreate(p, text, funct, data)text:按钮名称data:传递到函数的数据funct(b, data)b:the BCPushButton或BCToolButton将data储存在o中,通过key来调用
guitk.BCSetUserDataKey(o, key, data)o :对象,可以是widget或者layout,数据所储存的位置(指针)key:设置传递数据的名称(关键词,自己设置)data:要传递的数据,可以是变量、形参、或者字符串通过key来读取储存在对象o中的数据
guitk.BCGetUserDataKey(o, key) o:对象,可以是widget或者layoutkey:传递数据的名称o,keyimport ansa
from ansa import guitk
from ansa import constants
def main():
w = guitk.BCWindowCreate("UserDataKey Example", guitk.constants.BCOnExitDestroy)
blayout = guitk.BCBoxLayoutCreate(w, guitk.constants.BCHorizontal)
button1 = guitk.BCPushButtonCreate(blayout, "Set Caption 1", setCaption, w)
button2 = guitk.BCPushButtonCreate(blayout, "Set Caption 2", setCaption, w)
button3 = guitk.BCPushButtonCreate(blayout, "Set Caption 3", setCaption, w)
guitk.BCSetUserDataKey(button1, "key", "Caption 1")
# 在对象button1中将"Caption 1"存储在"key"中
guitk.BCSetUserDataKey(button2, "key", "Caption 2")
# 在对象button2中将"Caption 2"存储在"key"中
guitk.BCSetUserDataKey(button3, "key", "Caption 3")
# 在对象button3中将"Caption 3"存储在"key"中
guitk.BCBoxLayoutInsert(blayout, button1, -1)
guitk.BCBoxLayoutInsert(blayout, button2, -1)
guitk.BCBoxLayoutInsert(blayout, button3, -1)
guitk.BCShow(w)
def setCaption(b, window):
caption = guitk.BCGetUserDataKey(b, "key")
# 在对象中搜寻"key"代表的数据并存入caption
guitk.BCSetCaption(window, caption)
return 0
if __name__ == '__main__':
main()
CheckBox:复选框,是否勾选
BCCheckBoxCreateguitk.BCCheckBoxCreate(p, text)cbenable = guitk.BCCheckBoxCreate(w, "Enable Button")