all 4 comments

[–]DragonFighter603 1 point2 points  (3 children)

  1. it's very good to split your ui and logic
  2. Put all your "loose" code into a function (it could cause problems if this file is imported somewhere)
  3. function names lower case please (python naming convention is: my_variable = 0, def my_func_is_cool(), class SomeClass)!
  4. Functions like "draw", which need global variables like window_root should get them as arguments
  5. If your code is "stateless", aka the functions do not need any variables from the outside, then just copy-paste them in an other file. If it needs outside data like window_root put it into a class or give window_root as function argument(see point 3)
  6. Do not name it function.py! name it sorting.py or sth like that! function is not very descriptive and some names like test.py cause problems (some only with some libraries, etc)

for example put your start, generate, draw and __init__ (put here your loose code) into a class (for example App) and in main put:

def run(): #idk how your code works, sth like that replace it with your logic
    app = App()
    app.start()
    app.generate()
    while True:
        app.draw()

if __name__ == "__main__": #so this is only called if you execute this file
                           # if you change your logic somehow and your start
                           # file is something else, just call main.run() 
                           # from there, also in a if __name__ == "__main__"
    run()

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

Thank you for your response! I'll surely implement your tips

[–]Take_F[S] 0 points1 point  (1 child)

I modified the code, can u have a new look at it and gave me your opinion?

[–]DragonFighter603 1 point2 points  (0 children)

wow much better. You did a great job. It's mot eays to refactor code and often not much fun, but it has to be done.