[Tkinter-discuss] Tkinter-discuss Digest, Vol 35, Issue 10

Harlin Seritt harlinseritt at yahoo.com
Sun Jan 14 16:24:24 CET 2007


Hi Chris,

Looks like you're trying to do the same thing with 'f' and 'f1'. If so, you're telling it that f is a frame class without the grid method (though you do it tell it to "do" that later) while f1 is a frame class *including* the grid method you describe. 

>From my experience of doing this in the past, you make 'f1' be something besides a mere frame if this makes sense. Later on in your script this will cause some weirdness (at least to the developer) in it's behavior as a class. Although on a higher level it makes sense and I can easily see what you're doing and where you're going with it, the interpreter does not! 

That's where the weirdness comes in -- though it's not really weirdness -- an interpreter (even a very high level one like Python) follows a very strict protocol of how it assigns classes and such. Gee I feel like I went around the world on trying to explain that one.

Hope This Helps (If it doesn't, forget I ever existed ;-) )

Harlin Seritt


tkinter-discuss-request at python.org wrote: Send Tkinter-discuss mailing list submissions to
 tkinter-discuss at python.org

To subscribe or unsubscribe via the World Wide Web, visit
 http://mail.python.org/mailman/listinfo/tkinter-discuss
or, via email, send a message with subject or body 'help' to
 tkinter-discuss-request at python.org

You can reach the person managing the list at
 tkinter-discuss-owner at python.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Tkinter-discuss digest..."


Today's Topics:

   1. Confused by frames (Chris Niekel)
   2. Re: Confused by frames (Alexander Belchenko)


----------------------------------------------------------------------

Message: 1
Date: Sat, 13 Jan 2007 22:27:37 +0100
From: Chris Niekel 
Subject: [Tkinter-discuss] Confused by frames
To: Tkinter-discuss at python.org
Message-ID: <20070113212737.GE6314 at kira.niekel.net>
Content-Type: text/plain; charset=us-ascii

Hi,

I'm trying to combine a couple of widgets into a frame as a reusable
component. Somehow though, things change when I put some part in a class,
derived from Frame.

Version 1:

class F1(Frame):
    def __init__(self, *args, **kw):
        Frame.__init__(self, *args, **kw)
        Label(text="F1").grid(row=5,column=5)
r = Tk()

b = Button(r, text='button').grid(row=0,column=1)
f = F1(r).grid(row=0,column=0)
r.mainloop()

Version 2:

from Tkinter import *
r = Tk()

b = Button(r, text='button').grid(row=0,column=1)
f1 = Frame(r)
f1.grid(row=0,column=0)
Label(f1, text='F1').grid(row=5,column=5)
r.mainloop()


I would think these are equivalent, but they're not. Version 2 has the
behaviour I expect (a new frame, so the label is on the left).

Did I do something wrong in version 1, or is there another way to make a
class with the label which behaves like a frame?

Regards,
Chris


------------------------------

Message: 2
Date: Sun, 14 Jan 2007 02:49:16 +0200
From: Alexander Belchenko 
Subject: Re: [Tkinter-discuss] Confused by frames
To: tkinter-discuss at python.org
Message-ID: 
Content-Type: text/plain; charset=UTF-8

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Chris Niekel ?????:
> Hi,
> 
> I'm trying to combine a couple of widgets into a frame as a reusable
> component. Somehow though, things change when I put some part in a class,
> derived from Frame.
> 
> Version 1:
> 
> class F1(Frame):
>     def __init__(self, *args, **kw):
>         Frame.__init__(self, *args, **kw)
>         Label(text="F1").grid(row=5,column=5)

Last line contains error: you need to pass self as master for Label:

         Label(self, text="F1").grid(row=5,column=5)


> r = Tk()
> 
> b = Button(r, text='button').grid(row=0,column=1)
> f = F1(r).grid(row=0,column=0)
> r.mainloop()
> 
> Version 2:
> 
> from Tkinter import *
> r = Tk()
> 
> b = Button(r, text='button').grid(row=0,column=1)
> f1 = Frame(r)
> f1.grid(row=0,column=0)
> Label(f1, text='F1').grid(row=5,column=5)
> r.mainloop()
> 
> 
> I would think these are equivalent, but they're not. Version 2 has the
> behaviour I expect (a new frame, so the label is on the left).
> 
> Did I do something wrong in version 1, or is there another way to make a
> class with the label which behaves like a frame?
> 
> Regards,
> Chris

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFqX4MzYr338mxwCURAsJEAJ49MBKjVsSY5evFYivWAXih50rX2wCfZBsu
HBf9aPjq2tb8q6H2ln+6KUs=
=c1SZ
-----END PGP SIGNATURE-----



------------------------------

_______________________________________________
Tkinter-discuss mailing list
Tkinter-discuss at python.org
http://mail.python.org/mailman/listinfo/tkinter-discuss


End of Tkinter-discuss Digest, Vol 35, Issue 10
***********************************************


 
---------------------------------
Be a PS3 game guru.
Get your game face on with the latest PS3 news and previews at Yahoo! Games.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tkinter-discuss/attachments/20070114/fc83bf64/attachment.htm 


More information about the Tkinter-discuss mailing list