# TK custom events

**URL:** <https://www.ruby-forum.com/t/tk-custom-events/52279>\
**Category:** Ruby\
**Created:** [January 12, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/tk-custom-events/52279 "2006-01-12T14:16:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PWR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/977dab/32.png) [@PWR](https://www.ruby-forum.com/u/PWR)\
**Post date:** [January 12, 2006, 2:16pm UTC](https://www.ruby-forum.com/t/tk-custom-events/52279/1 "2006-01-12T14:16:40Z")

</div>

Hi, does anyone know how to set up a custom event which the Tk main  
loop will pick up i.e. I want to be able to create an event/handler  
which allows me to dispatch my own events to the Tk main loop. Any help  
gratfully received.

Peter.

---

<div class="post-metadata">

**Author:** ![PWR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/977dab/32.png) [@PWR](https://www.ruby-forum.com/u/PWR)\
**Post date:** [January 12, 2006, 3:01pm UTC](https://www.ruby-forum.com/t/tk-custom-events/52279/2 "2006-01-12T15:01:08Z")

</div>

From: “PWR” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: TK custom events.  
Date: Thu, 12 Jan 2006 22:13:18 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> Hi, does anyone know how to set up a custom event which the Tk main  
> loop will pick up i.e. I want to be able to create an event/handler  
> which allows me to dispatch my own events to the Tk main loop. Any help  
> gratfully received.

To answer your question, more details of your own events are required.  
Please explain what kind of events you want to treat.

---

<div class="post-metadata">

**Author:** ![PWR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/977dab/32.png) [@PWR](https://www.ruby-forum.com/u/PWR)\
**Post date:** [January 12, 2006, 5:43pm UTC](https://www.ruby-forum.com/t/tk-custom-events/52279/3 "2006-01-12T17:43:04Z")

</div>

What if i wanted to get the location of a file that i click and drag  
over  
lets say a TkButton?

Becker

---

<div class="post-metadata">

**Author:** ![PWR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/977dab/32.png) [@PWR](https://www.ruby-forum.com/u/PWR)\
**Post date:** [January 12, 2006, 3:44pm UTC](https://www.ruby-forum.com/t/tk-custom-events/52279/4 "2006-01-12T15:44:11Z")

</div>

I’m wanting to do the following,  
(1) Monitor an incoming socket with another thread and queue received  
messages.  
(2) Supply an event to the Tk mainloop when data arrives which causes  
it to call a handler which reads the queued data.

The idea is to avoid a solution which involves directly calling Tk  
methods from the other thread in case there are any thread safety  
issues. I may be being over cautious.

Peter.

---

<div class="post-metadata">

**Author:** ![PWR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/977dab/32.png) [@PWR](https://www.ruby-forum.com/u/PWR)\
**Post date:** [January 12, 2006, 6:28pm UTC](https://www.ruby-forum.com/t/tk-custom-events/52279/5 "2006-01-12T18:28:54Z")

</div>

Problem solved, in fact it never existed! Thanks a lot.

Peter.

---

<div class="post-metadata">

**Author:** ![PWR](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/977dab/32.png) [@PWR](https://www.ruby-forum.com/u/PWR)\
**Post date:** [January 12, 2006, 6:07pm UTC](https://www.ruby-forum.com/t/tk-custom-events/52279/6 "2006-01-12T18:07:37Z")

</div>

From: “PWR” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: Re: TK custom events.  
Date: Thu, 12 Jan 2006 23:43:05 +0900  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> The idea is to avoid a solution which involves directly calling Tk  
> methods from the other thread in case there are any thread safety  
> issues. I may be being over cautious.

Don’t worry about that. 🙂  
All Tk calls out of the ‘Tk.mainloop’ thread are automatically  
serialized on the event queue and done in the ‘Tk.mainloop’.  
That is not a work of a user, but a work of ‘tcltklib’.

Even though so, if you want to use your own event,  
please try TkVirtualEvent and Tk.event\_generate.  
If those cannot satisfy you, you may have to write C functions.  
If so, please read how to treat TclTkIp#invoke method on ‘tcltklib.c’.
