Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Tkx perl~tcl tied variables question
# This kind of thing works:
#    -textvariable => \$LABEL

# But this kind of thing, in a listbox, doesn't work:
#     -listvariable => \@LIST

# (If I had access to the Tkx $interp,
# I could write maybe
#   tie @PerlArray, Tcl::Var, $interp, "tclList", $flags;
# or something like that. )

# ------------------------------------------------------------------------
# The following (in the approved Tkx style)
# shows what I mean.
# (note: -justify doesn't work either.)

use strict;
use warnings;

use Tkx qw(MainLoop);
my $mw = Tkx::widget->new(".");

my $LABEL = "this is a label";
my $Label = $mw->new_label(-textvariable => \$LABEL);


my @LIST = ('this','is','a', 'list');

my $Listbox = $mw->new_listbox(
-borderwidth =>0,
-relief =>'flat',
-height => 10,
#-justify => 'right',
-listvariable => \@LIST,
);

$Listbox->insert('end','THIS');
$Listbox->insert('end','IS');
$Listbox->insert('end','A');
$Listbox->insert('end','LIST');

$Label->g_pack();
$Listbox->g_pack();

MainLoop

Report this thread to moderator Post Follow-up to this message
Old Post
~greg
03-14-08 09:34 AM


Re: Tkx perl~tcl tied variables question
On Mar 14, 4:05 am, "~greg" <g...@remove-comcast.net> wrote:
> #

You can either insert things directly into a listbox, or use a
listvariable,
but not both.  justify isn't a defined option for a listbox.  See the
docs:

http://www.tcl.tk/man/tcl8.5/TkCmd/listbox.htm

Here is working code using the correct Tk module:

use strict;
use warnings;
use Tk;

my $mw =  MainWindow->new;

my $LABEL = "this is a label";
my $Label = $mw->Label(-textvariable => \$LABEL);

my @LIST = ('this','is','a', 'list');

my $Listbox = $mw->Listbox(
-borderwidth =>0,
-relief =>'flat',
-height => 10,
-listvariable => \@LIST,
);

$Label->pack();
$Listbox->pack();

push @LIST, 'THIS','IS','A','LIST';

MainLoop;


Report this thread to moderator Post Follow-up to this message
Old Post
smallpond
03-15-08 12:23 AM


Re: Tkx perl~tcl tied variables question
"smallpond" <smallpond@juno.com> wrote in message news:20e19afd-8671-4611-b304-deb00af1cdca
@s50g2000hsb.googlegroups.com...
> On Mar 14, 4:05 am, "~greg" <g...@remove-comcast.net> wrote: 
>
> You can either insert things directly into a listbox, or use a
> listvariable,
> but not both.


When I change your push @LIST
to $Listbox->inserts ... in your "correct Tk module" example,
I get
"Cannot copy to ARRAY in entersub at..."

So it is true what you say.

Did you read about that somewhere? Or
did you have to find it out by testing?

(It's sort of strange behavior, I think,
in that either one can be used. But, after simply
using one, it precludes using the other.)

However, even when I remove the "insert" s from my original
"incorrect Tkx module" example, and try again, the "push" s
still doesn't work for me. In other words, for me, Tkx simply
does not successfully tie a perl array to a -listvariable at all.

> justify isn't a defined option for a listbox.  See the docs:
> http://www.tcl.tk/man/tcl8.5/TkCmd/listbox.htm

Ok.
But "-justify" *is* listed as "a standard option"
"When there are multiple lines of text displayed in a widget,"

- which I think *ought* to include listboxes, if nothing else.

Moreover, "-justify" *is*, explicitly, listed among the standard options
for Entry widgets. However, it doesn't work for me in them either
(when I use the incorrect Tkx module.)

I am beginning to think that Tkx.pm really may be the incorrect module,
as of the present.

Thanks,

~greg



>
> Here is working code using the correct Tk module:
>
> use strict;
> use warnings;
> use Tk;
>
> my $mw =  MainWindow->new;
>
> my $LABEL = "this is a label";
> my $Label = $mw->Label(-textvariable => \$LABEL);
>
> my @LIST = ('this','is','a', 'list');
>
> my $Listbox = $mw->Listbox(
>    -borderwidth =>0,
>    -relief =>'flat',
>    -height => 10,
>    -listvariable => \@LIST,
>    );
>
> $Label->pack();
> $Listbox->pack();
>
> push @LIST, 'THIS','IS','A','LIST';
>
> MainLoop;
>

Report this thread to moderator Post Follow-up to this message
Old Post
~greg
03-15-08 12:23 AM


Re: Tkx perl~tcl tied variables question
On Mar 14, 2:15 pm, "~greg" <g...@remove-comcast.net> wrote:
> "smallpond" <smallp...@juno.com> wrote in messagenews:20e19afd-8671-4611-b
304-deb00af1cdca@s50g2000hsb.googlegroups.com... 
> 
>
> When I change your push @LIST
> to $Listbox->inserts ... in your "correct Tk module" example,
> I get
>     "Cannot copy to ARRAY in entersub at..."
>
> So it is true what you say.
>
> Did you read about that somewhere? Or
> did you have to find it out by testing?
>
> (It's sort of strange behavior, I think,
> in that either one can be used. But, after simply
> using one, it precludes using the other.)
>

It may be an artifact of using the tie function, which
changes the way getting and storing values works.
But I'm just guessing.


> But "-justify" *is* listed as "a standard option"
>    "When there are multiple lines of text displayed in a widget,"
>

I think justify is only standard in widgets derived from Text
widgets, which Listbox isn't.


> I am beginning to think that Tkx.pm really may be the incorrect module,
> as of the present.
>
> Thanks,
>
> ~greg
>

Glad you are seeing the light.

I don't think there is much in Tk + Tix that isn't in perl/Tk
other than the new theme stuff in Tk 8.5.  Plus you don't have
funny tcl syntax.  Plus there are many contributed widgets
that aren't in tcl/tk.

--S

Report this thread to moderator Post Follow-up to this message
Old Post
smallpond
03-15-08 12:23 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PerlTk archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:57 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.