Class instances

richard_chamberlain at my-deja.com richard_chamberlain at my-deja.com
Mon Jun 26 10:37:54 EDT 2000


Sorry Egbert I didn't answer all of your questions.

>   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.

You are creating an instance of Knop by calling Knop(). Try doing that
interactively:

Knop
<class __main__.Knop at 8594c0>
>>> Knop()
<__main__.Knop instance at 85e590>

You are just not keeping a reference to it.

Sorry about the multiple postings, Deja lost it for a moment.

Richard




In article <20000626135336.A8180 at bork>,
  Egbert Bouwman <egbert at bork.demon.nl> wrote:
> 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
>
========================================================================
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list