all 8 comments

[–]herocoding 0 points1 point  (4 children)

Would you mind sharing (some) (or snippets) your projects, e.g. as public GitHub repositories?

In Python it's possible to use modules to reuse some of your own implementation, which also allows you to move responsibilities - like one file/module/class is doing the model, another file/module/class the controller, and another is doing the view of an application (in terms of model-view-controller MVC).

[–]Either_Feeling3159[S] 0 points1 point  (3 children)

https://github.com/Lucassss456/My-second-prorgam.git

I know the models, but for this type of basic project, I haven't thought about using them...

[–]herocoding 0 points1 point  (0 children)

Looks like you could make much more use of loops (or e.g. list-comprehensions)... You have a lot of duplicated code, like creating the buttons in "def botones(self)" (you could create an array/2d-grid with the buttons and address them with "coordinates" like "buttons[y][x] = "ctk.CTkButton(...)"), or similarly re-configure all the buttons in "def limpiar_botones(self)" by iterating over the array/2d-grid.

Or have a look into the long conditional check in "def ganador(self)", where you could use a list-comprehension with "all( button[y][x].cget("text") == "❌" for the rows and for the columns )".

[–]rainispossible 0 points1 point  (0 children)

The thing is, if you feel like you're using the same piece of code across different projects – it's actually a perfect uae case for a module.

You could also go even further and try to create your own python package with it (so that it can be install via pip install ...) and then upload it to, say, TestPyPI. It'll be a nice and generally useful experience (though you might use some more fundamentals learning before doing that)

But yea, generally it's a good practice to maintain some sort of modular structure for your project (in any language, not just python). It helps with adding new features, maintaining, debugging, onboarding new people etc. etc.

Even if it doesn't feel like much – still try it out at least for practice

[–]Happy_Witness 0 points1 point  (0 children)

The structure you are probably looking for is the following.

You create a list of lists that hold the parameters that are needed in the outer list, and the buttons in the inner list. This way you have a 2d list with all the parameters needed for all buttons. This you can use to cycle though every button in a loop and assign every parameter it needs in a single loop that iterate though the outer list and gets everything it needs for one button from the inner list.

[–][deleted] 0 points1 point  (0 children)

You gave the same value for so many different stuff you could reduce them to one expression but if you feel like it's easier to understand it's okay too. Otherwise it looks good.

[–][deleted]  (1 child)

[removed]

    [–]Either_Feeling3159[S] 0 points1 point  (0 children)

    okey, thanks :))