penmkr has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks: I am attempting to learn perl/tkx using activeperl v5.24.1 on a windows 10. None of the examples in the book "learn ring perl/tk" by Nancy Walsh, or the tutorial "tkdocs\tutorial\morewidgets.html", work as written but I have managed to get them working until this one. The tutorial states that tcl method '_tk__listbox' is the way to create a listbox using tkx. When I tried this I got an error "method '_tk__listbox' is reserved by tkx". I have no idea why this error is occurring or how to fix it. I have read everything I can find on the subject with no success. Can you please provide me with an explanation of this error and also the proper method for creating a listbox in tkx.

Replies are listed 'Best First'.
Re: creating a listbox in tkx
by kcott (Archbishop) on Oct 24, 2017 at 04:49 UTC

    G'day penmkr,

    Putting vague, incorrect references in your questions does you no favours at all. Some monks, who could provide (possibly expert) advice, may decide to match your effort and provide no help; others may attempt to search for book titles (and find they don't exist), or use a text-based URL in their browsers (and find it's invalid), then give up. The amount of effort you put into your question will directly reflect the quality of answers you receive: help us to help you. If you don't know how to create links here, see "What shortcuts can I use for linking to other information?".

    The book you refer to ("learn ring perl/tk") does not exist; I expect you mean Learning Perl/Tk. You say you have that book: it shows the correct title on the front cover, the spine, and the back cover; when you open the cover it's there again, and again when you turn the page, and again on the next page. There's absolutely no reason to get that wrong! It's also obvious that the publisher is O'Reilly (that appears in multiple places as well, along with their web address). Putting '"Learning Perl/Tk" site:oreilly.com' into my search engine gives, as the first result, "Learning Perl/Tk".

    Tk and Tkx are quite different modules. They both have a relationship to Tcl/Tk but it's very different. A book, or other reference, on Tk will not provide code you can use with Tkx; it may provide some ideas on underlying concepts.

    The thing that looks like a vague attempt at a URL ("tkdocs\tutorial\morewidgets.html") is completely bogus; I expect you mean http://www.tkdocs.com/tutorial/morewidgets.html. If you're looking at that page, just copy and paste the URL into your question here; I can't imagine a scenario where that's not easier than physically typing it yourself (and it's quite clearly less error-prone).

    "The tutorial states that tcl method '_tk__listbox' is the way to create a listbox using tkx."

    That is completely false. It does not say that at all. That page starts with a brief description of what a listbox is, followed by this (original emphasis unaltered):

    Listboxes are created using the new_tk__listbox method, a.k.a. Tkx::tk__listbox:

    $parent->new_tk__listbox(-height => 10)
    

    Code to instantiate a Listbox object appears once more in that section (in the full tutorial example):

    ... $lbox = $content->new_tk__listbox(-listvariable => \$cnames, -height = +> 5); ...
    " I have read everything I can find on the subject with no success."

    That doesn't tell us what you have read. I recommend the following.

    • CPAN: Tkx and Tkx::Tutorial. Read those in parallel; getting terse basics from the former and expanded explanations from the latter. I'd also recommend creating a module along the lines of what's described in "Subclassing Tkx::widget": it's a small, initial effort that has many benefits in the long run; also, you can start with a minimal version, then add to it as necessary.
    • TkDocs: It seems you've already found this. Start at the beginning: http://www.tkdocs.com/tutorial/ and work your way through each tutorial. Read what it says under "A Note on Coding Style" in "A First (Real) Example": the focus of the tutorials is Tcl/Tk, not Perl; monolithic GUI code works for short examples but runs into all sorts of problems with full-blown applications.
    • Tcl/Tk Documentation: Generally "Tcl/Tk Documentation"; in particular, "Tcl Commands" and "Tk Commands", both of which I recommend you have open in your browser as a reference when writing Tkx code. I've linked to the 8.6 version which, at the time of writing, appears to be the latest stable one (you may want something different). As you're using ActivePerl, I'm guessing you've also installed ActiveTcl, which will have installed the correct version of the documentation for whichever Tcl/Tk you're using (it's also quicker to load, uses no bandwidth, and is not prone to any internet-related issues).

    — Ken

Re: creating a listbox in tkx
by NetWallah (Canon) on Oct 24, 2017 at 00:21 UTC
    Googling shows that according to http://www.mynotebucket.com/perl-tkx/, the syntax is:
    my $lbox = $parent->new_tk__listbox(-listvariable => \$cnames, -height + => 5);

                    All power corrupts, but we need electricity.

Re: creating a listbox in tkx
by haukex (Archbishop) on Oct 23, 2017 at 19:42 UTC