From: Ronald Fischer Date: 2006-08-07T18:35:19+09:00 Subject: Ruby/Tk : How to show tooltips (please correct my ugly implementation) Could someone please help me with the following? I would like to add kind of a "show tooltips" function to my application, which means that some piece of text should be shown when the mourse moves over a certain area. In my case, the "hot spot" area is a set of TkLabel. When the mouse moves over such a label, a window should appear and show some text, and when the mouse leaves the label area, the window should disappear (this is different to "usual" tooltips, which appear and disappear on buttons, not on text labels, but the idea is the same). The text to be displayed, although different for each label, is static for the lifetime of the application. I found a solution which goes like this: require 'tk' class TestForm @hw=nil @root = TkRoot.new() { title("rtktest:TestForm") } @field1 = TkLabel.new(@root, :text => "field1").pack(); @field1.bind("Enter", proc {|e| puts("Entering field1") @hw=TkToplevel.new() helptext=TkLabel.new(@hw,:text=>"This is an example helptext").pack(); } ) @field1.bind("Leave", proc {|e| puts("Leaving field1") @hw.destroy @hw=nil } ) end TestForm.new Tk.mainloop I don't like this code for various reasons: First, TkToplevel has a full window decoration, but a tooltip would look better without a border etc. Secondly, a TkLabel is not suitable for multiline text. I would prefer something like a TkText, which formats text automatically according to window size; but TkText allows the user to edit the text and I would like to have a widget which just displays multiline text, but disallows editing. Does someone know a better way how to create my tooltip window? Finally, is it a good solution to pass the handle of my tooltip window via the class variable (@hw) from the creation procedure to the destroy procedure? Every type of critics wellcome.... Ronald -- Ronald Fischer Posted via http://www.newsoffice.de/