Tk: Call mainloop twice

Rubies:

The following code, when the user hits <Alt+F4> or clicks the little close
gadget on your window, destroys the TkRoot singleton, so everything below
the first Tk.mainloop won’t work:

require ‘tk’

canvas = TkCanvas.new() {width(400);height(300) }
TkcText.new(canvas, 100, 200) { text ‘hello world’ }
canvas.grid

canvas.bind(‘Destroy’) { |event|
puts "going down"
return if event.widget != @canvas
Tk.quit
}

Tk.mainloop

canvas = TkCanvas.new() {width(400); height(300) }
TkcText.new(canvas, 200, 100) { text ‘hello world’ }
canvas.grid
Tk.mainloop

The second call to TkCanvas.new dies with:

bgerror failed to handle background error.
Original error: c:/ruby/lib/ruby/1.7/tk.rb:358:in `call’: return from
proc-closure
Error in bgerror: can’t invoke “toplevel” command: application has been
destroyed

Witness my feeb attempt to tell the Tk.mainloop to gracefully exit instead
of destroy everything inside itself. I tried to bind to the Destroy event.

We may presume that the Destroy event itself takes down the Tk context. In
this case, maybe there is some other event I can bind to, or some other
binding site.

I would prefer, for elaborate & irrelevant reasons, not to just add a
stinkin’ button one can click on to call the Tk.quit. And experiments with
Tk.callback_break likewise bomb. Experiments opening another window, so the
first Tk.mainloop would still feel useful when the canvas goes down, also
failed.

···


Phlip
http://www.c2.com/cgi/wiki?TestFirstUserInterfaces

I understand your problem because I have the same.
Good luck to your program

I understand your problem because I have the same.

May I ask something?

I know why I have this problem. But why on earth would a normal person have
this problem??

···


Phlip
http://www.c2.com/cgi/wiki?TestFirstUserInterfaces

I understand your problem because I have the same.

Keep one window alive, so the mainloop never ends.
If you hide it, user won’t be bothered.
Haven’t checked whether this works.

May I ask something?

I know why I have this problem. But why on earth would a normal person have
this problem??

experimenting? especially in irb :slight_smile:

I had success once with a renewed “load ‘tk’”, but I haven’t
checked whether that has memory problems or other weird effects.

Bye,
Kero.

···

On Tue, 27 May 2003 13:17:46 +0000, Phlip wrote:

I’m an other problem with mainloop : I close a window (topLevel, not
Root) and when the root is alone, my CPU is used at 100%, How making?

···

I understand your problem because I have the same.

Keep one window alive, so the mainloop never ends.
If you hide it, user won’t be bothered.
Haven’t checked whether this works.

May I ask something?

I know why I have this problem. But why on earth would a normal person have
this problem??

experimenting? especially in irb :slight_smile:

I had success once with a renewed “load ‘tk’”, but I haven’t
checked whether that has memory problems or other weird effects.

Bye,
Kero.