By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,275 Members | 1,745 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,275 IT Pros & Developers. It's quick & easy.

Frame widget (title and geometry)

P: n/a
Hi,

I am still new to Python and Tkinter, so I apologize in advance if I do not word my question optimally. I am trying to use a frame widget as the parent for other widgets. There is a class with the header "class classtitle(Frame):" in a script called classtitle.py. Having imported classtitle, I create a Frame widget within my gui using the command "w = Frame(self)." Then, I grid this widget and issue the command "classinstance = classtitle.classtitle(w)." When I attempt to execute this code, I receive an error claiming that w lacks geometry and title attributes that the code in classtitle.py attempts to access. Does this mean that I cannot use a Frame widget as w in this situation? Thanks for your help.

Shankar

Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Fri, 24 Jun 2005 10:21:01 -0400, Shankar Iyer (si***@Princeton.EDU) <si***@Princeton.EDU> wrote:
Hi,

I am still new to Python and Tkinter, so I apologize in advance if I do not
word my question optimally. I am trying to use a frame widget as the parent
for other widgets. There is a class with the header "class classtitle(Frame):"
in a script called classtitle.py. Having imported classtitle, I create a Frame
widget within my gui using the command "w = Frame(self)." Then, I grid this
widget and issue the command "classinstance = classtitle.classtitle(w)." When
I attempt to execute this code, I receive an error claiming that w lacks
geometry and title attributes that the code in classtitle.py attempts to access.
Does this mean that I cannot use a Frame widget as w in this situation? Thanks
for your help.


Please post a short script showing the behavior you get. Without this, we cannot help you much. The only thing I can tell you right now is that you obviously don't need to create a Frame via "w = Frame(self)": since you defined your classtitle class as a sub-class of frame, every instance of classtitle is also an instance of Frame, so you can use it as such:
from Tkinter import *
root = Tk()
class MyClass(Frame): .... pass
.... o = MyClass(root)
o.grid()
just works. If you have to add anything in the constructor, do not forget to call the constructor for Frame in it, as in:
class MyClass(Frame):

.... def __init__(self, *args, **options):
.... Frame.__init__(self, *args, **options)
.... ## Other stuff...
....

If you do that, everything should be OK.

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in 'U(17zX(%,5.zmz5(17;8(%,5.Z65\'*9--56l7+-'])"
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.