我希望在我的tcltk窗口中插入一个'加载'的GIF图像,但是我无法绕过它。以下是一个可重复的例子: -
backg <- 'white'
pdlg <- tktoplevel(background=backg)
tcl('wm', 'geometry', pdlg, '500x100+450+350')
tilg <- 'Package installation in progress'
tkwm.title(pdlg, tilg)
fn <- tkfont.create(family = 'helvetica', size = 12)
nwlabel <- " The requisite packages are being installed. This may take several \nminutes... \n"
tllab <- tklabel(pdlg, text = nwlabel, font = fn, pady = 0, background=backg)
clickEv <- tclVar(0)
OK.but <- tkbutton(pdlg, text=' Stop ', command=function() tclvalue(clickEv) <- 1, font=fn, background='grey', pady=0)
tkgrid(tllab, columnspan=1)
tkgrid(OK.but, row=3)
tkbind(pdlg, "<Destroy>", function() tclvalue(done) <- 2)
tkfocus(pdlg)
#This allows me to insert a GIF image but the animation is lost. Also it would be convenient if the output can be obtained using 'tkgrid' instead of 'tkpack'
pdlg2 <- tktoplevel(background='white')
loading <- tclVar()
tcl('image', 'create', 'photo', loading,
file='file path to GIF file')
trial <- tklabel(pdlg2, image=loading)
tkpack(trial)
可以从这里下载示例GIF文件-http://www.dlfpramericalife.com/library/images/final_loading_big.gif
理想情况下,GIF图像应放在“停止”按钮上方但在文本下方。非常感谢你的帮助!
答案 0 :(得分:1)
在Tcl / Tk中,这很容易。
set img [image create photo -file nameofthefile.gif]
label .l -image $img
我不知道R,但是以你的代码作为指导,我想像这样的东西,但请检查一下!
img <- tkimage.create('photo', file='nameofthefile.gif')
imglab <- tklabel(pdlg, image = img)
...然后你将网格/打包/放置在任何你想要的地方。请注意,这不适用于GIF动画,我认为动画必须是手动处理程序,使用定时更新图像内容的计时器,但我从未做过,也不知道该怎么做。您可以查看Tcl/Tk wiki以获取更多帮助。