* LablTk problem
@ 2001-02-02 15:37 wester
2001-02-05 8:20 ` wester
0 siblings, 1 reply; 3+ messages in thread
From: wester @ 2001-02-02 15:37 UTC (permalink / raw)
To: caml-list
Hi,
I want to make a little Tk application. I have a main frame, a
menu frame with a menu button, a menu and a menu command.
Within the menu frame there is also a button. Besides this I have
a canvas. The button works, when pressing it, the application exits.
But the menu command doesn't react at all. I also tried the demo.ml
program in the otherlibs\labltk\example directory. Here the menu
command doesn't work too. I run an ocamltop with libltk.cma linked in
under WindowsNT.
I would be very appreciative for help.
With kind regards.
Rolf Wester
------------------------------------------------------------------------------------------------------------
#directory "h:\programme\ocaml30\lib\labltk";;
#labels true;;
let mainWindow () =
let top = Tk.openTk() in
let menuFrame = Frame.create top ~width: 20 ~height: 20 ~background: `Red in
Tk.pack ~side: `Top ~fill: `X [menuFrame];
let fileButton = Menubutton.create menuFrame ~text:"File" ~borderwidth:3 ~relief: `Groove in
Tk.pack ~side: `Left [fileButton];
let fileMenu = Menu.create fileButton in
Menu.add_command fileMenu ~label:"Exit..." ~command: (fun () -> closeTk (););
let exitButton = Button.create menuFrame ~text: "Exit" ~borderwidth:3 ~relief: `Ridge in
Tk.pack ~side: `Right [exitButton];
bind ~events:[`ButtonPress] ~action: (fun ev -> closeTk ();) exitButton;
let canvas = Canvas.create top ~width: 600 ~height: 400 ~background: `White in
Tk.pack [canvas];
canvas;;
let canvas = mainWindow ();;
Tk.mainLoop ();;
-------------------------------------
Rolf Wester
wester@ilt.fhg.de
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: LablTk problem
2001-02-02 15:37 LablTk problem wester
@ 2001-02-05 8:20 ` wester
2001-02-06 1:22 ` Jacques Garrigue
0 siblings, 1 reply; 3+ messages in thread
From: wester @ 2001-02-05 8:20 UTC (permalink / raw)
To: caml-list
Rolf Wester (that's me) wrote:
> Hi,
>
> I want to make a little Tk application. I have a main frame, a
> menu frame with a menu button, a menu and a menu command.
> Within the menu frame there is also a button. Besides this I have
> a canvas. The button works, when pressing it, the application exits.
> But the menu command doesn't react at all. I also tried the demo.ml
> program in the otherlibs\labltk\example directory. Here the menu
> command doesn't work too. I run an ocamltop with libltk.cma linked in
> under WindowsNT.
>
> I would be very appreciative for help.
>
> With kind regards.
>
> Rolf Wester
>
> ------------------------------------------------------------------------------------------------------------
>
> #directory "h:\programme\ocaml30\lib\labltk";;
> #labels true;;
>
> let mainWindow () =
> let top = Tk.openTk() in
>
> let menuFrame = Frame.create top ~width: 20 ~height: 20 ~background: `Red in
> Tk.pack ~side: `Top ~fill: `X [menuFrame];
>
> let fileButton = Menubutton.create menuFrame ~text:"File" ~borderwidth:3 ~relief: `Groove in
> Tk.pack ~side: `Left [fileButton];
> let fileMenu = Menu.create fileButton in
> Menu.add_command fileMenu ~label:"Exit..." ~command: (fun () -> closeTk (););
>
> let exitButton = Button.create menuFrame ~text: "Exit" ~borderwidth:3 ~relief: `Ridge in
> Tk.pack ~side: `Right [exitButton];
> bind ~events:[`ButtonPress] ~action: (fun ev -> closeTk ();) exitButton;
>
> let canvas = Canvas.create top ~width: 600 ~height: 400 ~background: `White in
> Tk.pack [canvas];
> canvas;;
>
> let canvas = mainWindow ();;
> Tk.mainLoop ();;
>
Sorry it was my fault, I found the problem. I simplified things a
little bit in the above example. The program as it is works fine.
But when I was testing the program I made the following:
Thread.start Tk.mainLoop();;
And now the menus don't work any more. What I want to do is start
a Tk application in it's own thread and be able to draw to the canvas
interactively at the sam time. If I press one the simple buttons the
application stops, only the menus don't work.
Rolf
-------------------------------------
Rolf Wester
wester@ilt.fhg.de
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: LablTk problem
2001-02-05 8:20 ` wester
@ 2001-02-06 1:22 ` Jacques Garrigue
0 siblings, 0 replies; 3+ messages in thread
From: Jacques Garrigue @ 2001-02-06 1:22 UTC (permalink / raw)
To: wester; +Cc: caml-list
From: wester@ilt.fhg.de
> Sorry it was my fault, I found the problem. I simplified things a
> little bit in the above example. The program as it is works fine.
> But when I was testing the program I made the following:
>
> Thread.start Tk.mainLoop();;
>
> And now the menus don't work any more. What I want to do is start
> a Tk application in it's own thread and be able to draw to the canvas
> interactively at the sam time. If I press one the simple buttons the
> application stops, only the menus don't work.
We are sorry, but ocamltk and labltk are not reentrant, so you cannot
use threads with them. Having a thread running the Tk mainloop and all
Tk calls and callbacks, while all other threads do some other work
seems to be safe (I actually use it in the Win32 version of
ocamlbrowser), but as soon as you call Tk functions in other threads
you're dead.
On Unix, Tcl/Tk provides two kinds of callbacks that may help you do
thread-like work: timeouts (module Timer) and fileinputs (module
Fileevent). They allow you to program in a non-blocking
way. Unfortunately, fileinputs do not seem to work on windows.
If you really want to use threads, you should look at lablgtk, which
is reentrant, and allows any kind of funny thing you might want to do
with threads.
Jacques Garrigue
---------------------------------------------------------------------------
Jacques Garrigue Kyoto University garrigue at kurims.kyoto-u.ac.jp
<A HREF=http://wwwfun.kurims.kyoto-u.ac.jp/~garrigue/>JG</A>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2001-02-06 16:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-02-02 15:37 LablTk problem wester
2001-02-05 8:20 ` wester
2001-02-06 1:22 ` Jacques Garrigue
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox