in reply to Re: Tkx and clear a textbox content
in thread Tkx and clear a textbox content

G'day zentara,

"Doesn't $textbox->delete(0, "end") work?"

Whilst that is valid syntax, the OP hasn't written his code to take advantage of it. Instead of a Perl widget handle like $textbox, a Tcl pathname, like '.c.textbox', has been used. As per "Calling Tcl and Tk Commands", the required syntax would need to be the rather clunky:

Tkx::i::call('.c.textbox', 'delete', 0 => 'end');

Given the way the OP's code has been written, I think huck's solution of assigning empty strings is a better option. Unless I wanted to target just a portion of the displayed text, I'd probably choose variable modification over accessing an index-based range.

Having said that, the OP's code has many problems, not least of which is the monolithic approach, with global variables just springing into existence without any regard for their scope. I wouldn't have written it like that to start with; in fact, the method described in the Tkx::Tutorial's section "Subclassing Tkx::widget" is a small amount of up-front work but results in much shorter, and easier to read, GUI code. Instead of code like:

Tkx::ttk__entry(".frame.textbox", ...); Tkx::grid(".frame.textbox", ...); ... Tkx::i::call('.frame.textbox', 'function', ...);

You can write something closer to:

my $textbox = $frame->entry(...)->grid->(...); ... $textbox->function(...);

Even with something as simple as the OP's GUI (5 entry, 5 label and 2 button widgets), the reduction in the amount of GUI code that needs to be written, and the improved readability, is clear.

— Ken

Replies are listed 'Best First'.
Re^3: Tkx and clear a textbox content
by zentara (Cardinal) on Aug 22, 2017 at 12:16 UTC
Re^3: Tkx and clear a textbox content
by jasonwolf (Sexton) on Aug 22, 2017 at 14:16 UTC

    Thank you for your suggestions, and clear example. Also for taking the time to detail the different methods. I will be honest, I am not sure what is the correct way to program with the TCL/TK format as you point out. I am only using the Example from the TKDoc link

    http://www.tkdocs.com/tutorial/firstexample.html

    however, I do have the "Introducing Perl/TK" book coming soon via mail. Yet, I am totally lost as to use Tk or Tkx - the syntax does appear to be different. What method do you recommend?