MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Buttons and Overwriting a Cell

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105600] Re: Buttons and Overwriting a Cell
  • From: dh <dh at metrohm.com>
  • Date: Thu, 10 Dec 2009 04:59:04 -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

> 

Hi Gregory,

here is a not too elegant solution.

First all tagged cells are located and deleted. Then a new cell is 

written with a tag.



Button["Hit Me",

  NotebookFind[ButtonNotebook[], "ButtonOut", All, CellTags];

  If[Options[NotebookSelection[]] =!= $Failed, NotebookDelete[] ];

  CellPrint[

   ExpressionCell[TableForm[RandomInteger[{0, 9}, {2, 2}]],

    CellTags -> "ButtonOut"]]

  ]



Daniel




  • Prev by Date: Re: Problem with FramedStyle when using inside Framed[]
  • Next by Date: Re: Play Command Error
  • Previous by thread: Re: Buttons and Overwriting a Cell
  • Next by thread: Re: Buttons and Overwriting a Cell