ttkcombobox

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

ttkcombobox

Sundar Dorai-Raj
Hi, all,

(sessionInfo at the end)

I've been struggling with the tcltk package and can't seem to get the
ttkcombobox to work. Here's an example:

library(tcltk)
p <- tktoplevel()
l <- tclVar()
## I don't know if I'm even calling it correctly
cb <- ttkcombobox(p, values = letters[1:4], textvariable = l)
tkpack(cb)

1. How do I know when the value of the combobox has been changed from,
say, "a" to "b"?
2. How can I get the value of the box? E.g. if I switch the box to "b",
how can I access this value?
3. How can I set the default value to something of my choice? I've tried
the "set" argument as described in the "Tcl/Tk 8.5 Manual" but I
received an error:
cb <- ttkcombobox(p, values = letters[1:4], textvariable = l, set = "b")
Error in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"),
class = "tclObj") :
   [tcl] unknown option "-set".

Thanks,

--sundar

 > sessionInfo()
R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252

attached base packages:
[1] tcltk     stats     graphics  grDevices utils     datasets  methods
[8] base

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ttkcombobox

Greg Snow-2
Here is one example of using ttkcombobox, hopefully it helps:

library(tcltk)

have.ttk <- function () { # from Prof. Ripley
    as.character(tcl("info", "tclversion")) >= "8.5"
}


testfunc <- function() {
        tt <- tktoplevel()
        if( !have.ttk() ) stop( "Need version 8.5 or greater of tcl" )

        tkpack(tklabel(tt, text='Choose a package'), side='top')

        tmp <- tclVar()
        tclvalue(tmp) <- 'TeachingDemos'

        tkpack(ttkcombobox( tt, values=c('blockrand',
                'ObsSens','TeachingDemos','sudoku'), textvariable=tmp ),
                side='left' )

        tkpack(tkbutton(tt,text='print',command=function() print(tclvalue(tmp))))
        tkpack(tkbutton(tt,text='exit', command=function() tkdestroy(tt)),side='right')
}


testfunc()

If you want something to happen when you change the combobox (rather than just getting the value when you press a button or something else), then you will probably have to use tkbind to bind an event to it, or use tkafter to check it on a regular basis.  I usually do as above and just have a button or something else run the code when I want and it just gets the current value.

Hope this helps,


--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
[hidden email]
801.408.8111


> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Sundar Dorai-Raj
> Sent: Monday, October 27, 2008 3:02 PM
> To: [hidden email]
> Subject: [R] ttkcombobox
>
> Hi, all,
>
> (sessionInfo at the end)
>
> I've been struggling with the tcltk package and can't seem to get the
> ttkcombobox to work. Here's an example:
>
> library(tcltk)
> p <- tktoplevel()
> l <- tclVar()
> ## I don't know if I'm even calling it correctly
> cb <- ttkcombobox(p, values = letters[1:4], textvariable = l)
> tkpack(cb)
>
> 1. How do I know when the value of the combobox has been changed from,
> say, "a" to "b"?
> 2. How can I get the value of the box? E.g. if I switch the box to "b",
> how can I access this value?
> 3. How can I set the default value to something of my choice? I've
> tried
> the "set" argument as described in the "Tcl/Tk 8.5 Manual" but I
> received an error:
> cb <- ttkcombobox(p, values = letters[1:4], textvariable = l, set =
> "b")
> Error in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"),
> class = "tclObj") :
>    [tcl] unknown option "-set".
>
> Thanks,
>
> --sundar
>
>  > sessionInfo()
> R version 2.7.2 (2008-08-25)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
> States.1252;LC_MONETARY=English_United
> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>
> attached base packages:
> [1] tcltk     stats     graphics  grDevices utils     datasets  methods
> [8] base
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ttkcombobox

Sundar Dorai-Raj
Hi, Greg,

Yes, that helps immensely!

Thanks,

--sundar

Greg Snow said the following on 10/27/2008 7:14 PM:

> Here is one example of using ttkcombobox, hopefully it helps:
>
> library(tcltk)
>
> have.ttk <- function () { # from Prof. Ripley
>     as.character(tcl("info", "tclversion")) >= "8.5"
> }
>
>
> testfunc <- function() {
>         tt <- tktoplevel()
>         if( !have.ttk() ) stop( "Need version 8.5 or greater of tcl" )
>
>         tkpack(tklabel(tt, text='Choose a package'), side='top')
>
>         tmp <- tclVar()
>         tclvalue(tmp) <- 'TeachingDemos'
>
>         tkpack(ttkcombobox( tt, values=c('blockrand',
>                 'ObsSens','TeachingDemos','sudoku'), textvariable=tmp ),
>                 side='left' )
>
>         tkpack(tkbutton(tt,text='print',command=function() print(tclvalue(tmp))))
>         tkpack(tkbutton(tt,text='exit', command=function() tkdestroy(tt)),side='right')
> }
>
>
> testfunc()
>
> If you want something to happen when you change the combobox (rather than just getting the value when you press a button or something else), then you will probably have to use tkbind to bind an event to it, or use tkafter to check it on a regular basis.  I usually do as above and just have a button or something else run the code when I want and it just gets the current value.
>
> Hope this helps,
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> Statistical Data Center
> Intermountain Healthcare
> [hidden email]
> 801.408.8111
>
>
>> -----Original Message-----
>> From: [hidden email] [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Sundar Dorai-Raj
>> Sent: Monday, October 27, 2008 3:02 PM
>> To: [hidden email]
>> Subject: [R] ttkcombobox
>>
>> Hi, all,
>>
>> (sessionInfo at the end)
>>
>> I've been struggling with the tcltk package and can't seem to get the
>> ttkcombobox to work. Here's an example:
>>
>> library(tcltk)
>> p <- tktoplevel()
>> l <- tclVar()
>> ## I don't know if I'm even calling it correctly
>> cb <- ttkcombobox(p, values = letters[1:4], textvariable = l)
>> tkpack(cb)
>>
>> 1. How do I know when the value of the combobox has been changed from,
>> say, "a" to "b"?
>> 2. How can I get the value of the box? E.g. if I switch the box to "b",
>> how can I access this value?
>> 3. How can I set the default value to something of my choice? I've
>> tried
>> the "set" argument as described in the "Tcl/Tk 8.5 Manual" but I
>> received an error:
>> cb <- ttkcombobox(p, values = letters[1:4], textvariable = l, set =
>> "b")
>> Error in structure(.External("dotTclObjv", objv, PACKAGE = "tcltk"),
>> class = "tclObj") :
>>    [tcl] unknown option "-set".
>>
>> Thanks,
>>
>> --sundar
>>
>>  > sessionInfo()
>> R version 2.7.2 (2008-08-25)
>> i386-pc-mingw32
>>
>> locale:
>> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
>> States.1252;LC_MONETARY=English_United
>> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>>
>> attached base packages:
>> [1] tcltk     stats     graphics  grDevices utils     datasets  methods
>> [8] base
>>
>> ______________________________________________
>> [hidden email] mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: ttkcombobox

Punitha-2
In reply to this post by Greg Snow-2
CONTENTS DELETED
The author has deleted this message.