tcltk
Mit dem Paket tcltk
(R Development Core Team) kann man grafische Benutzeroberflächen (GUI) programmieren.
-
Man installiere das Paket
tcltk
. tcltk läuft unter dem X Window System (X11) (Linux, MacOS X) und unter Windows. -
Hier ein Beispiele:
Beispiel 1:
require(tcltk)
handler.exit<-function(h,...) {
tkdestroy(window)
}
handler.ok<-function(h,...) {
x<-as.numeric(tclvalue(zahl))+5
tkconfigure(result, textvariable=tclVar(x))
}
window<-tktoplevel()
tkwm.title(window, "Beispiel 1")
zahl<-tclVar(5)
result<-tclVar(0)
tkpack(tkentry(window, textvariable=zahl))
tkpack(ttkbutton(window, text="Exit", command=handler.exit))
tkpack(ttkbutton(window, text="OK", command=handler.ok))
tkpack(result<-ttklabel(window, text="")) -
Weitere Beispiele findet man unter [7].
gWidgetstcltk
-
Man installiere die Pakete
gWidgets
undgWidgetstcltk
. tcltk läuft unter dem X Window System (X11) (Linux, MacOS X) und unter Windows. -
Mit
options("guiToolkit"="tcltk")
kann man ein Toolkit auswählen, falls mehrere Toolkits verfügbar sind. (fürgWidgetsRGtk2
: RGtk2; fürgWidgetsrJava
: rJava) [3] -
Hier zwei Beispiel:
Beispiel 1:
require(gWidgetstcltk)
options("guiToolkit"="tcltk")
e<-environment()
window<-gwindow("Beispiel 1", visible=FALSE)
f<-ggroup(cont=window, horizontal=FALSE)
g<-ggroup(cont=f, horizontal=TRUE)
h<-ggroup(cont=f, horizontal=FALSE, expand=TRUE)
handler_ok<-function(h,...) {
x<-as.numeric(svalue(e$zahl))+5
svalue(e$zahl)<-x
svalue(e$ergebnis)<-x
print(x)
}
handler_exit<-function(h,...) {
dispose(window)
}
e$zahl<-gedit("5", cont=g, expand=TRUE)
gbutton("OK", cont=g, handler=handler_ok)
gbutton("Exit", cont=g, handler=handler_exit)
e$ergebnis<-glabel("5", cont=h, expand=TRUE)
visible(window)<-TRUE
Beispiel 2:
require(gWidgetstcltk)
options("guiToolkit"="tcltk")
e<-environment()
e$data<-data.frame(A=c(1,6,3,8,4,7), B=c(5,5,5,5,5,5), C=c(2,3,4,5,1,2))
window<-gwindow("Beispiel 2", visible=FALSE)
f<-ggroup(cont=window, horizontal=FALSE)
g<-ggroup(cont=f, horizontal=TRUE)
h<-ggroup(cont=f, horizontal=FALSE)
handler_ok<-function(h,...) {
boxplot(e$data)
}
addSpring(g)
gbutton("OK", cont=g, handler=handler_ok)
grafik<-ggraphics(cont=h)
size(grafik)<-c(300,300)
visible(window)<-TRUE
gWidgetsRGtk2
Mit den Paketen RGtk2
(Michael Lawrence und Duncan Temple Lang), gWidgets
(John Verzani) und gWidgetsRGtk2
(Michael Lawrence und John Verzani) kann man grafische Benutzeroberflächen (GUI) programmieren.
-
Man installiere das Paket
RGtk2
. Bei der Installation vonRGtk2
kann man auch GTK+ mitinstallieren. GTK+ läuft unter dem X Window System (X11) (Linux, MacOS X) und unter Windows. -
Man installiere die Pakete
gWidgets
undgWidgetsRGtk2
. -
Mit
options("guiToolkit"="RGtk2")
kann man ein Toolkit auswählen, falls mehrere Toolkits verfügbar sind. (fürgWidgetstcltk
: tcltk; fürgWidgetsrJava
: rJava) [3] -
Hier zwei Beispiele:
Beispiel 1:
require(RGtk2)
require(gWidgetsRGtk2)
options("guiToolkit"="RGtk2")
e<-environment()
window<-gwindow("Beispiel 1", visible=FALSE)
f<-ggroup(cont=window, horizontal=FALSE)
g<-ggroup(cont=f, horizontal=TRUE)
h<-ggroup(cont=f, horizontal=FALSE, expand=TRUE)
handler_ok<-function(h,...) {
x<-as.numeric(svalue(e$zahl))+5
svalue(e$zahl)<-x
svalue(e$ergebnis)<-x
print(x)
}
handler_exit<-function(h,...) {
dispose(window)
}
e$zahl<-gedit("5", cont=g, expand=TRUE)
gbutton("OK", cont=g, handler=handler_ok)
gbutton("Exit", cont=g, handler=handler_exit)
e$ergebnis<-glabel("5", cont=h, expand=TRUE)
visible(window)<-TRUE
Beispiel 2:
require(RGtk2)
require(gWidgetsRGtk2)
options("guiToolkit"="RGtk2")
e<-environment()
e$data<-data.frame(A=c(1,6,3,8,4,7), B=c(5,5,5,5,5,5), C=c(2,3,4,5,1,2))
window<-gwindow("Beispiel 2", visible=FALSE)
f<-ggroup(cont=window, horizontal=FALSE)
g<-ggroup(cont=f, horizontal=TRUE)
h<-ggroup(cont=f, horizontal=FALSE)
handler_ok<-function(h,...) {
boxplot(e$data)
}
addSpring(g)
gbutton("OK", cont=g, handler=handler_ok)
grafik<-ggraphics(cont=h)
size(grafik)<-c(300,300)
visible(window)<-TRUE
Quellen: | |
[1] | RGtk2, Download, reference manual, Michael Lawrence, Duncan Temple Lang http://cran.mirroring.de/web/packages/RGtk2/index.html Zugriff: 11.7.2009 |
[2] | gWidgets, Download, reference manual, John Verzani http://cran.mirroring.de/web/packages/gWidgets/index.html Zugriff: 11.7.2009 |
[3] | Examples for gWidgets, John Verzani http://cran.r-project.org/web/packages/gWidgets/vignettes/gWidgets.pdf Zugriff: 11.7.2009 |
[4] | gWidgetsRGtk2, Download, reference manual, Michael Lawrence, John Verzani http://cran.mirroring.de/web/packages/gWidgetsRGtk2/index.html Zugriff: 11.7.2009 |
[5] | GTK+, Download http://www.gtk.org/index.php Zugriff: 11.7.2009 |
[6] | Beispiele für gWidgets http://wiener.math.csi.cuny.edu/pmg/gWidgets/Examples Zugriff: 11.7.2009 |
[7] | Beispiele für tcltk http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples Zugriff: 2.8.2010 |
2.8.2010 (R: R: 2.9.1, 2.11.1)