[Tutor] replacement for .mainloop() in Tk

Alan Gauld alan.gauld at btinternet.com
Mon Sep 3 09:25:11 CEST 2007


"Trey Keown" <trey at opmstech.org> wrote

> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> from Tkinter import *
> import tkFileDialog
> #<<<<<Main stuff>>>>>#
> self = Tk()

Using self here is a little bit unconventional sinmce its not in
a class. That could confuse some readers.

> self.title("Example Window Title")
> self.iconbitmap("e.ico")
> #<<<<<Get to work on button function!!!>>>>>#
> #<<<<<End window self>>>>>#
> #<<<<<End section>>>>>#
> #<<<<<End program>>>>>#
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

> Now, as you probably see, there isn't a "self.mainloop()"
> function in the output. My question is-
> *Is there any other thing I could use instead of ".mainloop()" to 
> make a
> window come up? Because I noticed that only one window can be up at 
> a time
> that has a ".mainloop()" attribute.

I'm not sure what you mean by that. You can have as many
windows as you like but there can only be one mainloop call,
usually on the top level tk object not on a window at all.

The mainloop is the event loop of the program. Without that
Tk cannot capture any events and hence can't do anything.
But why would having a mainloop be a problem? You can call
it at the end of your code. (In fact you can call it at the
beginning if you like! The end is just convention - and it does
make inserting new controls etc less problematic)

I'm slightly confused by what you are asking.
What is the problem that you think you have?


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 




More information about the Tutor mailing list