Perl/Tk button관련하여 재문의 드립니다.(왕초보)

bluesolip의 이미지

안녕하세요. Perl왕초보입니다.
Perl에 대해 잘 몰라 노가다로 여러번 시도 해봤지만 잘 안되어 문의 드립니다.
아래 소스에서 자동으로 버튼이 눌려지도록 eventGenerate() event를 넣었습니다.
어디에서 문제인지 수행이 안됩니다.
이런 문제까지 올리는게 조금 창피하지만 도움 부탁드립니다.

MakeFrame('test1','$tab12');
MakeButton("Update\ntest2",'&test3');

sub MakeFrame {
my($parent,$expression);
$frame = "\$$_[0]_fr";
$parent = $_[1];
$expression = "$frame = $parent->Frame( -relief => \'groove\',
-bd => 2)->pack( -side => \'top\',
-fill => \'both\',
-anchor => 'w'
);";
eval $expression;
}

sub MakeButton {
local($expression);
$expression = "$frame->Button( -text => \'$_[0]\',
-command => \\$_[1])->pack( -side => \'left\'); ";
eval $expression;

$test1_fr->eventGenerate('');
$test1_fr->eventGenerate('');
$test1_fr->eventGenerate('');

PS. 추가로 sub함수의 return값은 어디에 저장되나요?

keedi의 이미지

도움되시길 바랍니다. :)

#!/usr/bin/perl
 
use strict;
use warnings;
use Tk;
 
my $mw = MainWindow->new;
$mw->title( 'Perl/Tk :)' );
 
$mw->Label( -text => 'Generating Events' )->pack;
 
my $frame = $mw->Frame;
$frame->pack;
 
my $no = 0;
 
my $button = $frame->Button(
    -text    => 'Real Event',
    -command => sub {
        ++$no;
        print "clicked $no times.\n";
    },
)->pack(-side => 'left');
 
$frame->Button(
    -text    => 'Virtual Event',
    -command => sub {
        $button->eventGenerate('<Enter>');
        $button->eventGenerate('<ButtonPress-1>');
        $button->eventGenerate('<ButtonRelease-1>');
    },
)->pack(-side => 'left');
 
$frame->Button(
    -text    => 'Quit',
    -command => sub { exit },
)->pack(-side => 'left');
 
MainLoop;

---------------------------
Smashing Watermelons~!!
Whatever Nevermind~!!

Keedi Kim

----
use perl;

Keedi Kim

bluesolip의 이미지

우선 답변 감사드립니다.
코드를 돌려보니 제가 원한게 아닌거 같습니다.
제가 하고 싶은건 위에서 button을 만들고 나서 소스 맨마지막에서 위에 만들었던 button에 자동으로 button press, release event를 날릴 수 있도록 하고 싶습니다.

알고 계시면 댓글 부탁드립니다.

keedi의 이미지

예제로 올린 소스는 다른 버튼을 이용해서 옆의 버튼의 이벤트를 발생합시킵니다.
$button->eventGenerate() 부분이 자동으로 button press/release 하는 부분인데
이벤트를 날리는 코드를 원하셨던게 아닌가요? 흠...

---------------------------
Smashing Watermelons~!!
Whatever Nevermind~!!

Keedi Kim

----
use perl;

Keedi Kim

bluesolip의 이미지

감사드립니다.
물론 원하는 코드인데요. 예제 소스는 자동으로 이벤트를 발생시키기 위해 또다른 버튼을 눌러야 하잖아요. 근데 그렇게 하지않고 소스 맨마지막에서 누르지 않고 위에 선언한 버튼을 자동으로 발생시키게 만드는 겁니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.