Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6386741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:03:50+00:00 2026-05-25T03:03:50+00:00

In my, admittedly limited, experience with OO GUI programming (mostly with JAVA and Tkinter),

  • 0

In my, admittedly limited, experience with OO GUI programming (mostly with JAVA and Tkinter), I’ve noticed that in some code all widgets are assigned to instance attributes, while in other code, few if any are.

For example, in A Simple Hello World Program from the Tkinter chapter of the python docs, both buttons are assigned to instance attributes of the Application class:

class Application(Frame):
    ...

    def createWidgets(self):
        self.QUIT = Button(self)
        ...
        self.hi_there = Button(self)
        ...

    def __init__(self, master=None):
        Frame.__init__(self, master)
        ...
        self.createWidgets()

On the other hand, the Dialog Windows chapter of the Tkinter book defines a dialog support class with none of its widgets assigned to instance attributes:

class Dialog(Toplevel):
    def __init__(self, parent, title = None):
        Toplevel.__init__(self, parent)
        ...
        body = Frame(self)
        ...
        self.buttonbox()
        ...
    ...
    def buttonbox(self):
        ...
        box = Frame(self)

        w = Button(box, ...)
        ...
        w = Button(box, ...)
        ...
    ...

Question Statement

What are the pros/cons of each approach, and are there situations where it would make more sense to use one approach instead of the other?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:03:51+00:00Added an answer on May 25, 2026 at 3:03 am

    My rule of thumb is simple: if you are going to need to reference it later, make it an attribute. If not, don’t.

    I’m not sure I can enumerate any pros or cons with that approach — neither saving all references nor saving only the ones you need is particularly good or bad, it’s mostly a matter of style.

    That being said, however, making an attribute for a widget may imply it is used elsewhere. If it is not used elsewhere, people may make inferences about your code that are not true.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my admittedly young career I've found myself writing code to support quirky business
This is admittedly a rather loose question. My current understanding of singletons is that
My understanding of REST (admittedly limited to pretty much the wikipedia page ) is
(The title is admittedly not that great. Please forgive my English, this is the
I'm admittedly favour DIV, but am working on a project that uses nested tables.
I have a big mess of code. Admittedly, I wrote it myself - a
Admittedly I am just kind of hacking here so I would like some knowledge.
I'm parsing some text (admittedly HTML, but it's small stuff, and RegEx (should) do
I have the below code that was working fine until I tried adding the
ScottGu indicated in an admittedly old post that databinding to anonymous types just works

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.