## These cannot be run by examples() but should be OK when pasted
## into an interactive R session with the tcltk package loaded
## Run these commands one at a time
WinAdd("tt", title = "A Tk window with toolbars", pos ="-40+20")
ImgReadPackage("svWidgets") # Make sure images are loaded
# Create a toolbar and populate it
ToolAdd("$Tk.tt/Main")
ToolNames()
(ToolItems("$Tk.tt/Main")) # Still nothing in it
ToolAddItem("$Tk.tt/Main", "List variables",
action = "print(ls(envir = .GlobalEnv))", image = "$Tk.butCopy")
ToolAddItem("$Tk.tt/Main", "Say yo!", action = "cat('yo!\n')")
ToolAddItem("$Tk.tt/Main", "-")
ToolAddItem("$Tk.tt/Main", "Search",
action = "print(search())", image = "$Tk.butPaste")
(ToolItems("$Tk.tt/Main"))
# Change state of buttons in the toolbar
ToolStateItem("$Tk.tt/Main", "Search", FALSE)
ToolStateItem("$Tk.tt/Main", "Search", TRUE)
ToolStateItem("$Tk.tt/Main", "Say yo!", FALSE)
ToolStateItem("$Tk.tt/Main", "Say yo!", TRUE)
# Invoke a button
ToolInvoke("$Tk.tt/Main", "Say yo!")
# Remove a button and add another one (always at the end!)
ToolDelItem("$Tk.tt/Main", "Say yo!")
ToolAddItem("$Tk.tt/Main", "Say yo! twice", "cat('yo! yo!\n')")
(ToolItems("$Tk.tt/Main"))
ToolDel("$Tk.tt/Main")
ToolNames()
(ToolItems("$Tk.tt/Main"))
WinDel("tt")Run the code above in your browser using DataLab