如何在XPCE中按下按钮后打印功能结果

时间:2017-05-14 19:02:36

标签: prolog swi-prolog xpce

我正在尝试通过按下XPCE中的按钮来打印功能结果。这是我的代码:

/* 11) Max square */
max_square(M, A) :-
    findall(P, country(A, P, _, _), L),
    write('Max square in thousands km^2: '),
    aggregate(max(E), member(E, L), M),
    write(M),
    forall(country(A, M,_, _),format(',~w~n', [A])).

:- use_module(library(pce)).

test:-
    new(D, dialog),
    new(W,  window('Test', size(100, 100))),
    send(D, append, new(button(B, max_square, message(@prolog, max_square, M, A)))),
    send(D, below, W),
    send(D, open),
    !.

但我有这样的错误:http://imgur.com/a/9N546 我该怎么办呢?我的第二个问题是:是否可以在对话框窗口中打印此结果?提前谢谢。

1 个答案:

答案 0 :(得分:1)

这是可以做什么的一个例子

palindrome :-
    new(D, dialog('Palindrome')),
    new(Etiq, text_item('Is it a palindrome')),
    send(D, append, Etiq),
    new(Result, label),
    send(D, append, Result),
    send(D, append, button(test, message(@prolog, affiche, Etiq, Result))),
    send(D, append, button( cancel, message(D, destroy)) ),
    send(D, open).

affiche(Etiq, Result):-
    get(Etiq, selection, Text),
    atom_codes(Text, Str),
    (   reverse(Str, Str)
    ->   send(Result, selection, 'This is a palindrome')
    ;   send(Result, selection, 'This is not a palindrome')).