# Open web page from Ruby Tk app

**URL:** <https://www.ruby-forum.com/t/open-web-page-from-ruby-tk-app/137215>\
**Category:** Ruby\
**Created:** [May 10, 2008, 6:01am UTC](https://www.ruby-forum.com/t/open-web-page-from-ruby-tk-app/137215 "2008-05-10T06:01:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![e\_deleflie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/858c86/32.png) [@e\_deleflie](https://www.ruby-forum.com/u/e_deleflie)\
**Post date:** [May 10, 2008, 6:01am UTC](https://www.ruby-forum.com/t/open-web-page-from-ruby-tk-app/137215/1 "2008-05-10T06:01:20Z")

</div>

All,

I’m trying to avoid using TkHTML (too many dependencies in a  
cross-platform app).

I just want to click on a “link” (maybe a TkLabel with text underlined  
and in blue) … and open a URL in a web page.

- Does anyone have some sample code for opening a web page in the OS’s  
default browser?
- also, does anyone have any sample code on executing a proc on mouse  
down in a TKlabel?

any help is appreciated.

Etienne

---

<div class="post-metadata">

**Author:** ![e\_deleflie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/858c86/32.png) [@e\_deleflie](https://www.ruby-forum.com/u/e_deleflie)\
**Post date:** [May 10, 2008, 9:41am UTC](https://www.ruby-forum.com/t/open-web-page-from-ruby-tk-app/137215/2 "2008-05-10T09:41:43Z")

</div>

e deleflie wrote:

> - also, does anyone have any sample code on executing a proc on mouse  
> down in a TKlabel?

require ‘tk’

def on\_button\_press(e)  
widget = e.widget  
xcoord = e.x  
ycoord = e.y

puts “button pressed, x:#{xcoord}, y:#{ycoord}”  
end

root = TkRoot.new {  
title ‘Label Test’  
geometry “600x400+200+50”  
}

label = TkLabel.new(root) do  
text “click me”  
pack  
end

label.bind(‘ButtonPress-1’, lambda {|e| on\_button\_press(e)})  
label.bind(“ButtonRelease-1”, proc{puts “button released”})

Tk.mainloop
