From ggrothendieck at gmail.com  Fri Jul 10 02:03:53 2009
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Thu, 9 Jul 2009 20:03:53 -0400
Subject: [Rd] Changing text in a tkentry widget
In-Reply-To: <4A5667C4.5030002@rug.nl>
References: <mailman.11.1247133608.27074.r-devel@r-project.org> 
	<4A5667C4.5030002@rug.nl>
Message-ID: <971536df0907091703j1401e7ddg4aa896ca17f6ecdb@mail.gmail.com>

I assume that what is wanted is that "Anonymous" should
change to "changed name" when the "Change" button is pressed.

In that case enter this and then press the Change button
at which point "Anonymous" should change to "changed name".

library(tcltk)
tt <- tktoplevel()
Name <- tclVar("Anonymous")
entry.Name <-tkentry(tt, width = "20", textvariable = Name)
tkgrid(entry.Name)
OnChange <- function() {
	tclvalue(Name) <- "changed name"
}
Change.but <-tkbutton(tt,text="   Change   ",command = OnChange)
tkgrid(Change.but)
tkfocus(tt)



On Thu, Jul 9, 2009 at 5:57 PM, Richard Morey<r.d.morey at rug.nl> wrote:
> I searched the web and the list archives for a solution to this, but didn't
> see anything, so here goes. I'm new to tcltk. I'm trying to change the
> contents of a tkentry widget when a button is pressed. Once I get that
> working, the widget will be read only to the user. Here is some toy code:
>
> ###############
> require(tcltk)
> thisEnv=environment()
> tt<-tktoplevel()
> Name <- tclVar("Anonymous")
> entry.Name <-tkentry(tt,width="20",textvariable=Name)
> tkgrid(entry.Name)
> OnChange <- function()
> {
> ? assign("Name",tclVar("changed name"),thisEnv)
> }
> Change.but <-tkbutton(tt,text=" ? Change ? ",command=OnChange)
> tkgrid(Change.but)
> tkfocus(tt)
> ##################
> (much of this is taken from
> http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/editboxes.html)
>
> Now, I thought the whole point of the textvariable argument was to change
> the content of the tkentry widget. But, as you can see by running this code,
> changing the Name variable using assign does not change the content of the
> widget.
>
> Is there a function to update the content? tkinsert didn't seem to work when
> I tried it.
>
> Thanks,
> Richard Morey
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Changing text in a tkentry widget
Gabor Grothendieck