For Programmers: Free Programming Magazines  


Home > Archive > Tcl > November 2007 > tablelist: embed abutton in cells









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author tablelist: embed abutton in cells
luckygiurato@gmail.com

2007-11-27, 7:23 pm

Good evening,
I've a problem writing my application.

I'd like to use a tablelist.
I'm reading data from database and I visualize them on a table.
This works fine.
Now I'd like to embed a button in the cells of the first tablelist
column, to perform an action.
Buttons are visible but the associated action ("-command") isn't
executed.

Can someone help me?
Thank you
Csaba Nemethi

2007-11-27, 7:23 pm

luckygiurato@gmail.com schrieb:
> Good evening,
> I've a problem writing my application.
>
> I'd like to use a tablelist.
> I'm reading data from database and I visualize them on a table.
> This works fine.
> Now I'd like to embed a button in the cells of the first tablelist
> column, to perform an action.
> Buttons are visible but the associated action ("-command") isn't
> executed.
>
> Can someone help me?
> Thank you


Without knowing how you are creating and embedding the buttons, it is
hard to tell what's wrong with your code. Take a look at the demo script
"embeddedWindows.tcl", which is also discussed in detail in the
Tablelist Programmer's Guide. This script uses buttons embedded in one
of the columns of a tablelist widget, and the buttons do behave as expected.

--
Csaba Nemethi http://www.nemethi.de mailto:csaba.nemethi@t-online.de
luckygiurato@gmail.com

2007-11-28, 4:32 am


Thank you for the reply.
Before writing my code, I take a look to your demo code and to the
documentation.
I copied part your code.

This is a frame of "my" code, where I insert data extracted from the
database in the tablelist:
for { set i 0 } { $i < $list_dimesion } { incr i } {
set item [ lindex $my_list $i ]
set item [ linsert $item 0 "" ]
$tbl insert end $item
$tbl cellconfigure $i,0 -window createButton
}

proc createButton {tbl row col w} {
button $w -text "edit $row" -command [ puts "ROW: $row" ]
}

When I run the script, I see the table with data but:
- I can't see row number in botton text (-text option)
- when I press the button, I can't view the string on stdout

Have you any suggestion?
Can you tell me where is the mistake?
Thank you,
Luca



>
>
>
> Without knowing how you are creating and embedding the buttons, it is
> hard to tell what's wrong with your code. Take a look at the demo script
> "embeddedWindows.tcl", which is also discussed in detail in the
> Tablelist Programmer's Guide. This script uses buttons embedded in one
> of the columns of a tablelist widget, and the buttons do behave as expected.
>
> --
> Csaba Nemethi http://www.nemethi.de mailto:csaba.neme...@t-online.de


Bryan Oakley

2007-11-28, 8:11 am

luckygiurato@gmail.com wrote:
> Thank you for the reply.
> Before writing my code, I take a look to your demo code and to the
> documentation.
> I copied part your code.
>
> This is a frame of "my" code, where I insert data extracted from the
> database in the tablelist:
> for { set i 0 } { $i < $list_dimesion } { incr i } {
> set item [ lindex $my_list $i ]
> set item [ linsert $item 0 "" ]
> $tbl insert end $item
> $tbl cellconfigure $i,0 -window createButton
> }
>
> proc createButton {tbl row col w} {
> button $w -text "edit $row" -command [ puts "ROW: $row" ]
> }


Your problem is in the definition of the -command. You are saying "run
the command 'puts "ROW: $row"', and use the result of that as the value
for the -command option". That's almost certainly not what you intend.

Try this:

button $w -text "edit $row" -command [list puts "ROW: $row"]
luckygiurato@gmail.com

2007-11-28, 8:11 am

I tried both ways and I've the same result:
- No row number on the button text
- no output string

I tried even with command between "{}": same result too.

I'm sure that I write a wrong piece of code, but I don't understand
where is the mistake.

It seems that createButton procedure does't see its argoument, but
buttons are placed in the right place (first column of each line).

Thank you,
Luca


On 28 Nov, 13:17, Bryan Oakley <oak...@bardo.clearlight.com> wrote:
> luckygiur...@gmail.com wrote:
>
>
>
> Your problem is in the definition of the -command. You are saying "run
> the command 'puts "ROW: $row"', and use the result of that as the value
> for the -command option". That's almost certainly not what you intend.
>
> Try this:
>
> button $w -text "edit $row" -command [list puts "ROW: $row"]


Bryan Oakley

2007-11-28, 7:16 pm

luckygiurato@gmail.com wrote:
> I tried both ways and I've the same result:
> - No row number on the button text
> - no output string
>
> I tried even with command between "{}": same result too.
>


I recommend not to simply try different quoting mechanics. Instead, try
to understand what the problem is and figure out the right solution.
Just throwing different types of quotes at a problem isn't the best path
to success.

I assure you, the suggestion I made earlier is at least part of the
problem in your code.

> I'm sure that I write a wrong piece of code, but I don't understand
> where is the mistake.
>
> It seems that createButton procedure does't see its argoument, but
> buttons are placed in the right place (first column of each line).


When I typed in your createButton proc verbatim (except for the error
with the -command option I mentioned earlier), created some data that I
think simulates your data, and ran your loop exactly as you posted it,
it worked fine.

I'm not sure what that means, other than the true problem may not be in
the createButton procedure or the other code you posted.

My advice: try to write a very simple program that successfully uses
your createButton procedure. It can be done with a couple dozen lines of
code. Once you understand how to make the simple code work, hopefully it
will help you understand where the problem is in your real code.

The only other thing I can think of is that when you posted some code,
the definition of createButton came after it was first needed. I'm
hoping that is just a problem in you showing us the code and not a
problem in your actual code, because it needs to be defined before you
try to create the buttons.

Also, please tell us what version of tcl/tk you are using, and what
version of tablelist.

--
Bryan Oakley
http://www.tclscripting.com
luckygiurato@gmail.com

2007-11-28, 7:16 pm

Thank you for the quick response.

I think that my problem append before that I try to create the
buttons.

Anyway, I have:
Windows XP machine
ActiveState ActiveTcl 8.4.16.0.282109
Tablelist 4.8

Yours truly,
Luca
luckygiurato@gmail.com

2007-11-29, 4:34 am

I resolved the problem.

Thank you.

Yours truly,
Luca
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com