question about the mainloop

globalrev skanemupp at yahoo.se
Sun Apr 20 23:57:38 EDT 2008


On 21 Apr, 04:26, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Sun, 20 Apr 2008 20:24:04 -0300, globalrev <skanem... at yahoo.se> escribió:
>
> > in C?? java etc there is usually:
>
> > procedure 1
> > procedure 2
> > procedure 3
>
> > main {
> > procedure 1
> > procedure 2
> > procedure 3
> > }
>
> > i dont get the mainloop() in python. i mean i have written some
> > programs, for example a calculator using tkinterGUI.
>
> What you call the "mainloop" is the event loop (or message loop) used by event-driven applications as a way to dispatch all events as they happen in the system. The concept is independent of Python/C++/whatever language you choose. The key phrase is "event-driven programming":http://en.wikipedia.org/wiki/Event_driven_programming
> Tkinter provides an event-driven GUI framework. Simple CLI programs are not event-driven, as your pseudo example above.
>
> > if i have some functions i wanna call to run the program and i wanna
> > call them ina specific order and be able to call
> > them from each other should this just be called in the mainloop and
> > the mianloop then runs the "mainscript" top
> > to bottom over and over?
>
> If you don't want or don't require a graphical user interface, just write the functions you need and call them from the outermost section in your script.
> If you do require a GUI, you'll have to write the code in response to user actions: when the user clicks here, do this; when the user chooses that menu option, do that.
>
> --
> Gabriel Genellina


but what i mean i dont understand is sure i can bind a function to a
buttonpress but if i have a def dox(): dododo
 and i call it with dox() in the mainscript it will be executed once,
but not again.
so what does the mainloop do, 1srt time it is executed it runs the
mainscript then it it sits and wait s for commands?



More information about the Python-list mailing list