Ruby/Tk :: Root window backgrounds?

Is there a way to set a background img or color to your root window? I would like to use a img or color to give my app a desktop like feel. Is it possible, or is this something tk is lacking?

Tyler Mace

···


Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

Hi,

···

From: kryptik@usa.com
Subject: Ruby/Tk :: Root window backgrounds?
Date: Sun, 9 Mar 2003 17:57:02 +0900
Message-ID: 20030309085657.60426.qmail@mail.com

Is there a way to set a background img or color to your root window?
I would like to use a img or color to give my app a desktop like feel.
Is it possible, or is this something tk is lacking?

Well, maybe need a little tricky way.
The way is to use two geometry manager on same widget.
For example,

require ‘tk’
image = TkPhotoImage.new(‘file’=>‘background.gif’, ‘height’=>200, ‘width’=>200)
root = TkRoot.new
TkLabel.new(root, ‘image’=>image).place(‘in’=>root,
‘relheight’=>1.0, ‘relwidth’=>1.0)
TkButton.new(root, ‘text’=>‘TOP’).pack(‘side’=>‘top’)
TkButton.new(root, ‘text’=>‘BOTTOM’).pack(‘side’=>‘bottom’)
Tk.mainloop

Each of Place and Pack geometry manager doesn’t know other
geometry manager. So Pack geometry manager has no attention
to existence of the label widget with the image controlled
by Place geometry manager.

                              Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)

Hmm. That doesn’t seem like a very good idea. First of all, to the
extent that this trick works it is incidental, undocumented behavior
of the current implementation, thus subject to change without notice.
And I’m surprised that it would work at all. I’m fairly new to Ruby,
but have done a lot of Tcl/Tk and Tkinter (Python) work, and in those
languages if you use two geometry managers on the same widget it will
at least freeze up your application, and sometimes your whole
desktop. Maybe Ruby handles geometry manager conflicts more
gracefully.

In any case, I think there’s another way to do this.

  1. Create a toplevel window without title bars and all that junk (I
    forget exactly how you do that, but it’s documented … search
    the Wm manual page for “override redirect.” That should at
    least be a start.
  2. Display your image in the window.
  3. Lower the window (“down” being towards the root window, of
    course).
  • You may need to set a binding on the window such that it gets
    lowered again every time it becomes visible.

How well this technique works may depend on how well-behaved your
window manager is, but at least it relies on documented, intentional
features of Tk.

···

On 11 Mar 2003 at 13:46, nagai@ai.kyutech.ac.jp wrote:

From: kryptik@usa.com

Is there a way to set a background img or color to your root window?
I would like to use a img or color to give my app a desktop like feel.
Is it possible, or is this something tk is lacking?

Well, maybe need a little tricky way.
The way is to use two geometry manager on same widget.


Matt Gushee
Englewood, CO, USA

Hi,

···

From: mgushee@havenrock.com
Subject: Re: Ruby/Tk :: Root window backgrounds?
Date: Tue, 11 Mar 2003 14:40:10 +0900
Message-ID: 3E6D1447.19436.13F4223@localhost

And I’m surprised that it would work at all. I’m fairly new to Ruby,
but have done a lot of Tcl/Tk and Tkinter (Python) work, and in those
languages if you use two geometry managers on the same widget it will
at least freeze up your application, and sometimes your whole
desktop. Maybe Ruby handles geometry manager conflicts more
gracefully.

I’m sorry but I’ve had no experiment of freezing.
Ruby/Tk calls Tcl/Tk interpreter. If your Tcl/Tk freezes on your
environment, Ruby/Tk freezes too.

BTW, I’ve forgotten the simple and better way. :slight_smile:

  1. Create a label (or canvas, or … ) widget with the image,
    and pack it on the root widget.
  2. Create widgets which parent is the label widget, and pack them
    on the label widget.

    Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)