- Now call Tk.mainloop
^^ I think maybe that’s where I was going wrong. I wrote a unit test to
test the updating of the label. My code looked something like this:
class GraphicalProgress
def initialize
root = TkRoot.new { title ‘Progress’ }
@my_label = tkLabel.new(root)
@my_label.configure(‘text’=>‘Waiting for something to report…’)
@my_label.pack
Tk.mainloop
end
def update(message)
@my_label.configure(‘text’=>‘Waiting for something to report…’)
end
end
Unit Test:
@progress = GraphicalProgress.new
@progress.update(‘I’m doing something’)
@progress.update(‘I’m done’)
And because the loop is in the initialize method, only when the app is
closed do we get to the line which requests the text is update. Of
course this falls over as the widget has been destroyed…
So with your suggestion the code should be something like this…
class GraphicalProgress
def initialize
root = TkRoot.new { title ‘Progress’ }
@my_label = tkLabel.new(root)
@my_label.configure(‘text’=>‘Waiting for something to report…’)
@my_label.pack
end
def update(message)
@my_label.configure(‘text’=>‘Waiting for something to report…’)
end
end
Unit Test:
@progress = GraphicalProgress.new
@progress.update(‘I’m doing something’)
@progress.update(‘I’m done’)
Tk.mainloop
Or have I got the wrong end of the stick?
Thanks so much for your help!
Gem