## These cannot be run by examples() but should be OK when pasted
## into an interactive R session with the tcltk package loaded
## Examples of tk2ico - icon manipulation under Windows
tt2 <- tktoplevel()
# Load a system icon (there are: "application", "asterisk", "error",
# "exclamation", "hand", "question", "information", "warning", and "winlogo".
Warn <- tk2ico.load(res = "warning")
tk2ico.info(Warn)
# Change the text
tk2ico.text(Warn)
tk2ico.text(Warn) <- "Warning icon"
tk2ico.text(Warn)
# Get hicon
tk2ico.hicon(Warn)
# Change the icon of my window tt2
tk2ico.set(tt2, Warn)
# Do not forget to destroy icon to free resource when not needed any more
tk2ico.destroy(Warn)
rm(Warn)
# Load an icon from the resource section of an exe, or dll
Rico <- tk2ico.load(file.path(Sys.getenv("R_HOME"), "bin", "R.exe"), res = "R")
tk2ico.info(Rico)
tk2ico.set(tt2, Rico)
tk2ico.destroy(Rico)
rm(Rico)
# Load one or several icons from an .ico file
libdir <- file.path(.path.package(package = "tcltk2")[1], "gui")
SVico <- tk2ico.create(file.path(libdir, "SciViews.ico"))
# The various resolution icons created from this file
tk2ico.info(SVico)
# Change the default position to 1 (the second icon)
tk2ico.pos(SVico) <- 1
# Change only the small icon (use Alt-Tab to see the large one)
tk2ico.set(tt2, SVico, type = "small")
# Get the handle of the R Console window and change its icon
tk2ico.set(getWindowsHandle("Console"), SVico)
# Set a taskbar icon, with both a left and right-click menu
lmenu <- tkmenu(.TkRoot, tearoff = FALSE)
tkadd(lmenu, "command", label = "Say hello",
command = function() cat("Hello from taskbar!\n"))
rmenu <- tkmenu(.TkRoot, tearoff = FALSE)
tkadd(rmenu, "command", label = "Say hello again",
command = function() cat("Hello again from taskbar!\n"))
tk2ico.taskbar.add(SVico, pos = 1, text = "my R taskbar icon",
leftmenu = lmenu, rightmenu = rmenu)
# Try left and right-click on the taskbar icon...
# Change its text...
tk2ico.taskbar.modify(SVico, pos = 1, text = "text changed!")
#... and delete it
tk2ico.taskbar.delete(SVico)
# Destroy the icons
tk2ico.destroy(SVico)
rm(SVico)
# When done, dispose of the window and clean the workspace
tkdestroy(tt2)
rm(list = c("libdir", "lmenu", "rmenu", "tt2"))
Run the code above in your browser using DataLab