[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

help with TkRoot

Diego Virasoro

8/19/2006 8:16:00 AM

Hello,
I would like to write a program on the Mac which at the start only
shows the menubar: only after the user has selected an option from the
menu would the first window appear.

However I can't get that to work in Tk. It seems that a Tk GUI can't do
without a TkRoot widget and TkRoot is shown as a window.

Is there any way to make the TkRoot be the menubar itself? Or maybe to
make TkRoot invisible? Or any other solution to achieve the same goal?

Thank you.

Diego Virasoro

3 Answers

Morton Goldberg

8/19/2006 7:24:00 PM

0

Yes, you can make the root window invisible. The following produces a
default menu bar but no (visible) root window on my Mac:

require 'tk'

root = TkRoot.new
root.withdraw
Tk.mainloop

Regards, Morton

On Aug 19, 2006, at 4:20 AM, Diego Virasoro wrote:

> Hello,
> I would like to write a program on the Mac which at the start only
> shows the menubar: only after the user has selected an option from the
> menu would the first window appear.
>
> However I can't get that to work in Tk. It seems that a Tk GUI
> can't do
> without a TkRoot widget and TkRoot is shown as a window.
>
> Is there any way to make the TkRoot be the menubar itself? Or maybe to
> make TkRoot invisible? Or any other solution to achieve the same goal?


Morton Goldberg

8/19/2006 8:58:00 PM

0

Now that I've looked a little deeper into the problem, I see that
Tk.root.withdraw wouldn't be useful, because in your case, if you use
it, you won't see the root window's menu bar. What to do? Well, you
might try something like the following:

<code>
root = TkRoot.new {title 'Ruby Tk'}

mnu_bar = TkMenu.new()
windo_mnu = TkMenu.new(mnu_bar)
windo_mnu.add_command(
'label'=>"Show",
'command'=>lambda {windo_mnu.show}
)
windo_mnu.add_command(
'label'=>"Hide",
'state'=>'disabled',
'command'=>lambda {windo_mnu.hide}
)
def windo_mnu.show
entryconfigure(0, 'state'=>'disabled') # disable show
entryconfigure(1, 'state'=>'normal') # enable hide
Tk.root.geometry($visible)
end
def windo_mnu.hide
entryconfigure(1, 'state'=>'disabled') # disable hide
entryconfigure(0, 'state'=>'normal') # enable show
Tk.root.geometry("0x0+0+0")
end
mnu_bar.add_cascade('label'=>"Window", 'menu'=>windo_mnu)
root.menu(mnu_bar)

min_w, min_h = 200, 100
root.minsize(min_w, min_h)
root_x = (root.winfo_screenwidth - min_w) / 2
$visible = "#{min_w}x#{min_h}+#{root_x}+50"
root.geometry("0x0+0+0")

root.bind('Command-q') {exit}

Tk.mainloop
</code>

This is my best shot at the moment. It's not very elegant since you
can still see the vestigial root window in the upper left-hand corner
of the screen if you look hard, but perhaps it's good enough to fool
your users :)

Regards, Morton

On Aug 19, 2006, at 3:23 PM, Morton Goldberg wrote:

> Yes, you can make the root window invisible. The following produces
> a default menu bar but no (visible) root window on my Mac:
>
> require 'tk'
>
> root = TkRoot.new
> root.withdraw
> Tk.mainloop


Gregor Kopp

8/21/2006 6:29:00 AM

0

Diego Virasoro schrieb:
> Hello,
> I would like to write a program on the Mac which at the start only
> shows the menubar: only after the user has selected an option from the
> menu would the first window appear.
>
> However I can't get that to work in Tk. It seems that a Tk GUI can't do
> without a TkRoot widget and TkRoot is shown as a window.
>
> Is there any way to make the TkRoot be the menubar itself? Or maybe to
> make TkRoot invisible? Or any other solution to achieve the same goal?
>
> Thank you.
>
> Diego Virasoro
>

Maybe you could try to define the menubar in the root window with proper
size and then, if the entry in the menu is selected you could make a
toplevel.