Re: Buttons and Overwriting a Cell
- To: mathgroup at smc.vnet.net
- Subject: [mg105643] Re: Buttons and Overwriting a Cell
- From: David Bailey <dave at removedbailey.co.uk>
- Date: Sun, 13 Dec 2009 05:38:35 -0500 (EST)
- References: <hfleid$snr$1@smc.vnet.net>
Gregory Lypny wrote: > Hello everyone, > > I'm trying to create a button that will produce a 2x2 table of random integers, which I think I've succeeded in doing with the following. > > Button["Hit Me", Print[TableForm[{{RandomInteger[{2,12}], RandomInteger[{2,12}]}, > {RandomInteger[{2,12}], RandomInteger[{2,12}]}}, > TableHeadings->{Automatic,Automatic}]]] > > I'd also like it to overwrite any existing table that it has produced on a previous click. I know I need to set CellAutoOverwrite to True, but I'm not sure how to work that into my Button statement. Any suggestions would be much appreciated. > > Regards, > > Gregory > Probably the best way to do this, is to incorporate the button and the matrix inside one larger control: table = {{0, 0}, {0, 0}}; Column[{Button["Hit Me", table = {{RandomInteger[{2, 12}], RandomInteger[{2, 12}]}, {RandomInteger[{2, 12}], RandomInteger[{2, 12}]}}], Dynamic[TableForm[table, TableHeadings -> {Automatic, Automatic}]] }] David Bailey http://www.dbaileyconsultancy.co.uk