Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how do you create a modeless dialog with tcl/tk?

265 views
Skip to first unread message

Mark_Galeck

unread,
Aug 24, 2009, 2:52:12 PM8/24/09
to
Hello, I see that tk_dialog creates a dialog window, but it is
"modal", that is, waits for input from the user. I RTFM'd but cannot
find, ...

how to create a "modeless" dialog - so that the script goes on its
merry way, while the dialog sits there .

Thank you! Mark

Les Cargill

unread,
Aug 24, 2009, 3:24:00 PM8/24/09
to

Here's one way:

console show

toplevel .y

label .l -text "This is my main window, which is not involved in the
modeless dialog box"
grid .l

button .y.b1 -text "Here" -command {set ::ach(1) 1 }
button .y.b2 -text "There" -command {set ::ach(2) 2 }

array set ::ach { 1 0 2 0 }

trace variable ::ach w ::florg

proc florg { args } {
puts "florg <$args>"
parray ::ach
}


grid .y.b1 .y.b2 -sticky news


-----

Output looks like:

florg <::ach 1 w>
::ach(1) = 1
::ach(2) = 0
florg <::ach 2 w>
::ach(1) = 1
::ach(2) = 2
florg <::ach 1 w>
::ach(1) = 1
::ach(2) = 2
(modelessdialog) 1 %

-------

Within proc "::florg", you now get mapped button events
whenever each button is selected. This without resorting
directly to events on the buttons themselves.

You can do similar things with entry fields, the "-variable"
option therein and trace of that as well. And there are
other ways.

--
Les Cargill

Robert Heller

unread,
Aug 24, 2009, 4:00:22 PM8/24/09
to

Well, you start with a toplevel (just like a modal dialog):

toplevel .whatever
wm transient .whatever .

and you go from there.

The only difference from a modal dialog and a modeless dialog is whether
or not you use the 'grab' command on it.

>
> Thank you! Mark
>

--
Robert Heller -- 978-544-6933
Deepwoods Software -- Download the Model Railroad System
http://www.deepsoft.com/ -- Binaries for Linux and MS-Windows
hel...@deepsoft.com -- http://www.deepsoft.com/ModelRailroadSystem/

Mark_Galeck

unread,
Aug 24, 2009, 4:04:51 PM8/24/09
to
Thank you very much - this got me started in the right direction!

Thank you Robert too! I appreciate

Gerald W. Lester

unread,
Aug 24, 2009, 4:11:58 PM8/24/09
to

Mark,

Others have point you down the path of how to do what you want.

I want to point you down the path to enlightenment...

Other toolkits give you lots of specific widgets to do specific things. The
problem comes in if you can not find a widget that does exactly what you
want. In most cases you either have to change what you want or do a *lot*
of work (many times at a very low level).

Tk takes a different approach, it gives you components that you can put
together to do whatever you want it to do.

For example, Tk does not have a X/Y scrolled listbox. What we have is a
listbox and a scrollbar widget that can be combined easily to make:
1) a X/Y scrolled listbox
2) a Y only scrolled listbox
3) a X only scrolled listbox
3) an unscrolled listbox

The same concept (and normally option) can then be used to make many (but
not all) other widgets scroll.


--
+------------------------------------------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+

Robert Heller

unread,
Aug 24, 2009, 5:23:28 PM8/24/09
to
At Mon, 24 Aug 2009 13:04:51 -0700 (PDT) Mark_Galeck <mark_galeck...@yahoo.com> wrote:

>
> Thank you very much - this got me started in the right direction!
>
> Thank you Robert too! I appreciate

Have a look at dialog.tcl in the Tk library directory. One can just
copy this file, change the proc name and remove sections 7 and 8 (which
deal with the grabbing, waiting, and ungrabbing), and presto, a
modeless dialog!

0 new messages