如何在xpce / prolog中创建一个按钮来执行某些功能

时间:2012-12-21 09:30:17

标签: swi-prolog xpce

?- new(B, button(hello,
                 message(@pce, write_ln, hello))).

在xpce / prolog中,这是创建按钮来打印句子的方法 有什么办法,当我点击一个按钮,我想做一些功能,请帮忙!

1 个答案:

答案 0 :(得分:3)

来自Help > XPCE manual > Browsers > Examples > Obtainers +右键点击+ Select您可以看到一个实际的例子。

create_person_dialog :-
    new(D, dialog('Enter new person')),
    send(D, append, new(label)),    % for reports
    send(D, append, new(Name, text_item(name))),
    send(D, append, new(Age, text_item(age))),
    send(D, append, new(Sex, menu(sex, marked))),

    send(Sex, append, female),
    send(Sex, append, male),
    send(Age, type, int),

    send(D, append,
         button(create, message(@prolog, create_person,
                                Name?selection,
                                Age?selection,
                                Sex?selection))),

    send(D, default_button, create),
    send(D, open).

create_person(Name, Age, Sex) :-
    format('Creating ~w person ~w of ~d years old~n',
           [Sex, Name, Age]).

在打开突出显示create_person_dialog后,右键单击并Consult应该得到(我填写了一些值)

enter image description here

并点击控制台中的Create输出

Creating male person goofy of 99 years old

通常,您需要attach按钮到某个GUI才能获得其功能。

HTH

编辑这是我在Windows上获得的布局

enter image description here

方式获得了这两个图像的区别:在Windows中,我打开帮助主题后启用了上下文菜单Consult