Question on creating Tkinter Widgets

A

Adonis

I am creating some widgets by inheriting from Tkinter.Frame and populating
the frame with whatever the widget will be then creating certain
attributes/methods to be accessed later. My question is, is this a poper way
to create widgets or should I take a different approach?

Any help is greatly appreciated.

Adonis
 
E

Eric Brunel

Adonis said:
I am creating some widgets by inheriting from Tkinter.Frame and populating
the frame with whatever the widget will be then creating certain
attributes/methods to be accessed later. My question is, is this a poper way
to create widgets or should I take a different approach?

Any help is greatly appreciated.

Adonis

Most Tkinter "megawidgets" are created by either specializing Tkinter.Frame or
Tkinter.Canvas, so it seems to be the way to go. It has at least a major
advantage: the widgets you create directly inherit the basic behaviour of all
Tkinter widgets, so you can directly pack them, grid them, or whatever else,
without having a single line of code to write. I made some Tkinter widgets
myself and always used this approach; up to this time, it worked pretty well.

HTH
 
K

klappnase

Adonis said:
I am creating some widgets by inheriting from Tkinter.Frame and populating
the frame with whatever the widget will be then creating certain
attributes/methods to be accessed later. My question is, is this a poper way
to create widgets or should I take a different approach?

Any help is greatly appreciated.

Adonis

So far this sounds perfectly "proper" to me.
Usually when I create my own widgets it looks like:

class Mywidget(Tkinter.Frame):
def __init__(self, master, special_attribute='default', *args, **kw):
Tkinter.Frame.__init__(self, master, *args, **kw)
<widget's contents......>

def widget_method1(self):
<.......>

(etc.)

Sounds like you are doing quite the same.

Regards

Michael
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top