From: 7stud -- Date: 2008-04-14T14:00:09+09:00 Subject: Re: ruby/tk and loop delay Ed Redman wrote: > I am writing a card game in ruby/tk. > > I have a Tk_button(shuffle) that shuffles the cards and places them on a > canvas.The shuffle works fine but I would like to have a slight delay > between between each card being displayed on the canvas. Below is the > shuffle buttons command. I would like to delay the loop each time so > their is a slight delay. I have tried putting Tk.after(time) > { part around the loop} but it just delays the shuffle and is not > visible. Not each card being displayed. I need a little direction > on implementing such a loop > > thanks > > > > shuffle.command do > 52.times do > |i| > > nr = rand(56) > nm = rand(56) > io = newhash[nr] > im = newhash[nm] > # Tk.after(100) { > place[nr].image io > newhash[nm] = io > place[nr].image im > newhash[nr] = im > # } > end > > end Are you not supposed to use sleep() for some reason? This works for me: require 'tk' def do_press(e) widget = e.widget x = e.x y = e.y 10.times do x += 10 TkcLine.new(widget, x, y, x+100, y+100) widget.update sleep(2) end end root = TkRoot.new {title 'Canvas Test'} canvas = TkCanvas.new(root) canvas.pack canvas.bind('ButtonRelease-1', lambda {|e| do_press(e)}) Tk.mainloop -- Posted via http://www.ruby-forum.com/.