The automagic of Tkinter

Egbert Bouwman egbert at bork.demon.nl
Mon Jun 26 07:53:37 EDT 2000


Good afternoon,
The following small script does what I intended it to do:
it produces a button, and that button dissappears when i click on it.

    from Tkinter import *
    class Knop(Button):
       def __init__(self,tekst="KNOPJE"):
           Button.__init__(self,text=tekst,command=self.quit)
           self.pack(side=TOP,fill=BOTH,expand=YES)
    root=Tk()
    k=Knop()
    root.mainloop()

However when I replace the last three lines with only:
    Knop().mainloop()
then the script still works.

This leaves me with a number of questions (sorry, richard):
- if 'root=Tk()' is dispensable, then what is its builtin replacement
  and what does that replacement do
- up till now I saw a class object as a template, that has to be 
  instantiated in order to be of any use. However here it seems to 
  lead its own life.
- probably 'mainloop()' plays a crucial role here, but what are all
  its functions ?  What is the difference between 
  'root.mainloop()' and 'Knop().mainloop()'
I promised Richard to pose only one question per post, but these 
questions really are one big question about the Tkinter mechanism.
egbert

-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991
========================================================================




More information about the Python-list mailing list