Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1000999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:36:02+00:00 2026-05-16T07:36:02+00:00

I have been trying to define multiple combo boxes in R using the tcltk

  • 0

I have been trying to define multiple combo boxes in R using the tcltk package but to no avail. I am using the below code. My inspiration was here, however I can’t seem to just label them comboBox1, comboBox2, etc… so I decided to try and set their output values into a vector… but their output values don’t make any sense to me… any ideas out there?

many thanks

require(tcltk)
tclRequire("BWidget")
tt <- tktoplevel()
tkgrid(tklabel(tt,text="What's your favorite fruits?"))
fruit <- c("Apple","Orange","Banana","Pear")
num <- c(0:3)
num.fruit <- cbind(num, fruit)
#####1st box
comboBox <- tkwidget(tt,"ComboBox",editable=FALSE,values=num.fruit[,2])
tkgrid(comboBox)
Cbox1<- comboBox
tkfocus(tt)

######2nd box

comboBox <- tkwidget(tt,"ComboBox",editable=FALSE,values=num.fruit[,2])
tkgrid(comboBox)
Cbox2 <- comboBox
###

##preliminary wrap-ip to pass to OnOK function
pref1 <- tcl(Cbox1,"getvalue")
pref2 <- tcl(Cbox2,"getvalue")

  Prefs <- c(pref1,pref2)
######action on OK button
OnOK <- function()
{
    fruitChoice <- fruits[as.numeric(tclvalue(tcl(Prefs,"getvalue")))+1]

    tkdestroy(tt)
    msg <- paste("Good choice! ",fruitChoice,"s are delicious!",sep="")
    tkmessageBox(title="Fruit Choice",message=msg)

}
OK.but <-tkbutton(tt,text="   OK   ",command=OnOK)
tkgrid(OK.but)
tkfocus(tt)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T07:36:03+00:00Added an answer on May 16, 2026 at 7:36 am

    Why don’t you just use ttkcombobox?

    require(tcltk)
    tt <- tktoplevel()
    tkwm.title(tt, "Fruits!")
    tkwm.geometry(tt, "200x150+300+300") 
    
    onOK <- function()
        {
        fav <- tclvalue(favFruit)
        worst <- tclvalue(worstFruit)
    
        if (fav != "Choose one")
            tkmessageBox(title="Favorite fruit", message = paste("Your favorite fruit is", fav))
        if (worst != "Choose one")
            tkmessageBox(title="Worst fruit", message = paste("The fruit you like the least is", worst))
    
        if (fav == "Choose one" & worst == "Choose one")
            tkmessageBox(title="Well...", message = "Select a fruit!")
        }
    
    label1 <- tklabel(tt, text="What's your favorite fruit?")
    label2 <- tklabel(tt, text="What fruit you like the least?")
    
    fruits <- c("Choose one", "Apple", "Orange", "Banana", "Pear")
    # Default selections for the two combo boxes
    favFruit <- tclVar("Choose one")
    worstFruit <- tclVar("Choose one")
    
    # 1st box
    combo.1 <- ttkcombobox(tt, values=fruits, textvariable=favFruit, state="readonly") 
    # 2nd box
    combo.2 <- ttkcombobox(tt, values=fruits, textvariable=worstFruit, state="readonly") 
    # If you need to do something when the user changes selection just use
    # tkbind(combo.1, "<<ComboboxSelected>>", functionname)
    
    OK.but <- tkbutton(tt,text="   OK   ", command = onOK)
    
    tkpack(label1, combo.1)
    tkpack(label2, combo.2)
    tkpack(OK.but)
    
    tkfocus(tt)
    

    PS: personally, I abandoned tcltk in favour of RGtk2, much more flexible in my opinion and you can design interfaces visually using Glade Interface Designer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.