[R] Multicolumn Listbox selectcommand trouble

jefreier at berkeley.edu jefreier at berkeley.edu
Mon Mar 1 03:11:42 CET 2010


Hey folks,
This is my first message to the mailing list so please let me know if I
mess something up.

I'm trying to use the selectcommand for the mclistbox but I'm not very
adept at using functions. Ideally I'd like to change the editor text when
a different list item is selected but any help using the selectcommand
would be appreciated and I think I could get the rest working.

Thanks a lot.
John

UC Berkeley Student

Here's some links for thought
http://www1.clearlight.com/~oakley/tcl/
http://tech.groups.yahoo.com/group/tcl_announce/message/298

Here is is some of my code. I think selectcommand is supposed to go in the
tk2mclistbox()

totalcols = 5
totalrows = 100
idb <- matrix(NA, nrow = totalrows, ncol = totalcols, dimnames =
list(c(),c("Date","URL", "Title", "List Price", "Category")))


base <- tktoplevel()
listings <- tkframe(parent = base)
editor <- tkframe(parent = base)
tkwm.title(base, "my super program")

#changeeditor function(){
#	}


mlb <- tk2mclistbox(listings, height = 20, width = 95, resizablecolumns =
TRUE, yscrollcommand = function(...)tkset(scr1,...))

#?tk2mclistbox
# Define the columns
tk2column(mlb, "add", "date", label = "col1", width = 20)
tk2column(mlb, "add", "title", label = "col2", width = 40)
tk2column(mlb, "add", "listprice", label = "col3", width = 15)
tk2column(mlb, "add", "categ", label = "col4", width = 20)

# Collect data from insurance companies
scr1 <- tkscrollbar(listings, repeatinterval = 5, command =
function(...)tkyview(mlb,...))
tkgrid(mlb, scr1)
tkgrid.configure(scr1, stick = "ns")
tk2insert.multi(mlb, "end", idb[,c(1,2,3,4)])
tkpack(listings, side = "top")

txtviewer <- tktext(editor, font = "courier", width = 66, height = 20,
yscrollcommand = function(...)tkset(scr2,...))
scr2 <- tkscrollbar(editor, repeatinterval = 5, command =
function(...)tkyview(txtviewer,...))

tkgrid(txtviewer, scr2)
tkgrid.configure(scr2, sticky = "ns")
tkmark.set(txtviewer,"insert","0.0")
tkinsert(txtviewer,"end","This is some stuff")

DeleteSelection <- function()
{
    fruitIndex <- as.integer(tkcurselection(mlb))
    tkdelete(mlb,fruitIndex)
}
DeleteSelection.but <- tkbutton(editor,text="Delete",command=DeleteSelection)
tkgrid(DeleteSelection.but)


tkfocus(txtviewer)

tkpack(editor, side = "bottom")



More information about the R-help mailing list