[Tutor] grid manager question

David bouncingcats at gmail.com
Mon Feb 13 22:33:04 EST 2023


On Tue, 14 Feb 2023 at 12:46, Phil <phillor9 at gmail.com> wrote:
> On 14/2/23 08:54, David wrote:

> > See the demo example I showed in the other thread,
> > which has no App() class.

> I recently asked a question about the correct way to use Tkinter and ttk
> because there are a dozen ways to achieve the same result. That question
> was answered and is in agreement with an e-book that I bought a week
> ago: OOP being the preferred style although the e-book only contains one
> OOP example. To that end I have a number code templates, that I tweak
> when I find something better, that I use because I keep forgetting (it's
> an age thing) the correct syntax. I agree with you that it's a bit
> cluttered but isn't that the way the big boys programme?

I'm unsure exactly what "big boy" means, but I imagine they would be the
master of their own code, and that's the direction I'm trying to guide you
towards.

So the good news is, you found "something better", like you said above!

An App() class is one way to provide namespacing. It's not the only way.

If you are getting zero benefit from using an App() class, but it makes you
have to write 'self.' in front of oodles of variables where that otherwise
wouldn't be required, why clutter up your code with it?

Anyway, I'm going to drop that topic now. I only brought it up because
you seem to be somewhat lost in the weeds and I'm trying to help you
clarify and focus on what's important.

> I have played with your demo example and does exactly what I'd ask for.
> What I have in mind is a bit more complex than a button and a circle but
> it's a very good starting point.

My demo example shows how to create a custom widget class.  I intentionally
targetted exactly what you asked about, with a minimal example that would
be complete and educational.  Generally, I don't write code for people.
I made an exception for this question, because it seemed to be the most
efficient and direct way to open your eyes to what you said you wanted to
understand.

Custom made, just for you personally. I'm sorry it's not an e-book, maybe
next time :)

My aim was to give you something small that you could study until you
become 100% comfortable with every aspect of it and you understand it
completely. It demonstrates how to pass arguments to the custom widget, and
how the parent-child relationships are created, and how to subclass from
tk.Frame().

You can ask here about any aspect of that example that you have even the
slightest doubt about. Once that process completes, which hopefully won't
take long, I hope it will help you to write code that does what you want
instead of looking for examples and trying to hack them together.

If you don't do that, then I will realise that my approach to helping you
does not suit you, it will stop, and that's fine. Good luck!

My goal in replying to you today is to have you feel 100% confident about
every part of your code. Your code. Own it!


More information about the Tutor mailing list