question about the mainloop

Lie Lie.1296 at gmail.com
Tue Apr 22 04:37:10 EDT 2008


On Apr 21, 6:24 am, globalrev <skanem... at yahoo.se> wrote:
> 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.
>
> 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?

In Python+Tkinter (and I believe, all event-driven programming model),
the codes you write are all used for setting up the GUI, specifying
where they're placed, what happens when they're clicked, etc, etc,
etc. And entering the main loop means the event "manager" (a.k.a
mainloop) would start checking all the registered events and respond
to the event by calling the associated function you determined at the
setup. This event "manager" loops itself over and over until it
received an event that tells them to stop listening and quit the
program (usually binded with the close button).

In some event-driven programming model (like in Visual Basic, don't
know about Java, never used it), the setup phase is hidden from you
and is done automagically by the GUI designer, and when the setup
phase finishes (the mainloop is called), the first event that happens
is a programhasjuststarted event, which is automagically bound with a
startup function, in VB: the Main Form's OnLoad Event or a Main
function.



More information about the Python-list mailing list