use strict; use Tk; use Tk::DialogBox; #Character Variables. my $name = "Na"; my $health = "HP"; my $morality = "Mo"; my $willpower = "WP"; my $potency = "Po"; my $resource = "Re"; my $target = 0; # MainWindow my $mwin = new MainWindow(-background=>'black'); #Button for adding character information my $chrb = $mwin->Button(-text=>'Add Character',-activeforeground=>'bl +ack', -activebackground=>'green',-foreground=>'green',-backgroun +d=>'black', -command=>\&charadd) -> pack(-anchor=>'w'); #Canvas, which character info is drawn on. my $canv = $mwin->Scrolled('Canvas',width=>600,height=>600,-background +=>'black',-confine=>0) -> pack(); $canv->createLine(0,20,600,20,-fill=>'green'); #DialogBox, for when a new character is added. my $diag = $mwin->DialogBox(-title=>'Add Character',-buttons=>['Ok','C +ancel'], -default_button=>'Ok'); $diag->add('Entry',-textvariable=> \$name) -> pack(); $diag->add('Entry',-textvariable=> \$morality) -> pack(); $diag->add('Entry',-textvariable=> \$willpower) -> pack(); $diag->add('Entry',-textvariable=> \$potency) -> pack(); $diag->add('Entry',-textvariable=> \$resource) -> pack(); $diag->add('Entry',-textvariable=> \$health) -> pack(); Tk::MainLoop; #Maintain GUI. $canv->bind('<current>','<Button-1>', =>\&damage); our $charc = 0; sub charadd() { ++$charc; $canv->createText(20,($charc*60)+10,-text=>$charc,-fill=>'green'); $diag->Show(); $canv->createText(40,($charc*60)+10,-text=>$name,-fill=>'green'); $canv->createText(160,($charc*60)+10,-text=>"Po: $potency",-fill=> +'green'); $canv->createText(220,($charc*60)+10,-text=>"WP: $willpower",-fill +=>'green'); $canv->createText(280,($charc*60)+10,-text=>"Re: $resource",-fill= +>'green'); $canv->createText(360,($charc*60)+10,-text=>"Mo: $morality",-fill= +>'green'); for (my $i = 1; $i <= $health; $i++) { $canv->createRectangle($i*30,($charc*60)+20,($i*30)+20,($charc +*60)+40, -fill=>'green',-tag=>'hpbox'); } } sub damage() { }
It runs, but when I click on one of the healthboxes drawn it doesn't do anything.
Once the script ends it feeds me this huge error that ultimately ends in:
Usage $widget->bind(...) ... Derived.pm line 469

In reply to Tk Canvas Item Bind by JadedAegis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.