[R-gui] tktoplevel issues

Philippe Grosjean phgrosjean at sciviews.org
Tue Dec 4 17:49:51 CET 2007


Hello,

This works for me:

library(tcltk2)
tt <- tktoplevel(background = "black")
# Creates the body of the GUI.
ilogo <- tk2ico.load(file.path(Sys.getenv("R_HOME"), "bin", "R.exe"), 
res = "R")
tk2ico.set(tt, ilogo)	# This assigns the icon to the main window.
tktitle(tt) <- "Backtest"	# Creates a window title.
masterframe <- tkframe(tt)

#  Button
openwindow <- function(){
	ruv <- tktoplevel()
	.Tcl("update idletasks")	
   	tk2ico.set(ruv, ilogo)
	tktitle(ruv) <- "Test Window"
	
	topMenu <- tk2menu(ruv)
	
	fileMenu <- tk2menu(topMenu, tearoff = FALSE)
	tkadd(fileMenu, "command", label = "Quit", command =
		function()tkdestroy(ruv))
	tkadd(topMenu, "cascade", label = "File", menu = fileMenu)
	tkconfigure(ruv, menu = topMenu)
		
	MasterFrame2 <- tkframe(ruv)
	tkgrid(MasterFrame2)
}
test.but <- tkbutton(masterframe, text = "Run", command = openwindow)
tkpack(test.but, side = "top")

tkgrid(masterframe)

Comments:
1) Do not create same (graphical) resource twice, reuse it,
2) Declare your functions or objects before using them in tcl widgets
3) do not forget .Tcl("update idletasks") when required, especially with 
functions like tk2ico.set()

Best regards,

Philippe Grosjean

..............................................<°}))><........
  ) ) ) ) )
( ( ( ( (    Prof. Philippe Grosjean
  ) ) ) ) )
( ( ( ( (    Numerical Ecology of Aquatic Systems
  ) ) ) ) )   Mons-Hainaut University, Belgium
( ( ( ( (
..............................................................

Ruvashen Padayachee wrote:
> Hi there! I have a little problem regarding the tcltk2 package. I have
> created a simple GUI and a button within which, when pressed, opens up
> another window. The problem I have is that the icon I specify to appear
> in the second window does not appear. Do you have any idea why? 
>  
> Example code: 
>  
>  
> tt = tktoplevel(background = "black")
> # Creates the body of the GUI.
> tktitle(tt) = "Backtest"
> # Creates a window title.
> ilogo = tk2ico.create("H:/GUI/icons/ilogo.ico")
> # Icon created.
> tk2ico.set(tt,investeclogo)
> # This assigns the icon to the main window.
> masterframe = tkframe(tt)
> tkgrid(masterframe)
>  
> #  Button
> test.but = tkbutton(masterframe,text = "Run",command = openwindow)
> tkpack(test.but, side = "top") 
> 
>  
> openwindow = function(){
>  
> ruv = tktoplevel()                              
> tktitle(ruv) = "Test Window"          
> ilogo2 = tk2ico.create("H:/GUI/icons/ilogo.ico")
> tk2ico.set(ruv,ilogo2)         
>  
> topMenu = tk2menu(ruv)
> tkconfigure(ruv,menu = topMenu)
> fileMenu = tk2menu(topMenu, tearoff = FALSE)
> tkadd(fileMenu,"command", label = "Quit", command =
> function()tkdestroy(ruv))
> tkadd(topMenu,"cascade",label = "File", menu = fileMenu)
>  
> MasterFrame2 = tkframe(ruv)                          
> tkgrid(MasterFrame2)
>  
> }
>  
> Thanks and Regards! 
>  
>  
> 
> 
> 
> 
>  
>  
>  
> 
>  
> 
> http://www.investec.com/EmailDisclaimer/emaildisclaimer.htm
> 
> The disclaimer also provides our corporate information and names of our directors as required by law.
> 
> The disclaimer is deemed to form part of this message in terms of Section 11 of the Electronic Communications and Transactions Act 25 of 2002. 
> If you cannot access the disclaimer, please obtain a copy thereof from us by sending an email to: disclaimer at investec.co.za
> 	[[alternative HTML version deleted]]
> 
> _______________________________________________
> R-SIG-GUI mailing list
> R-SIG-GUI at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-gui
>



More information about the R-SIG-GUI mailing list