1

I want to clearly be able to see that my class LoginScrollbar is a class (also a tkinter Frame) composing of elements belonging to the LoginFrame and not for example the MainWindow which is launched after logging in as it is very unclear which classes are simpley frameworks to display elements under which Frame (main class). What is the best way to achieve this goal?

I don't know what to try.

This is my code I currently have, as you can see it's very unclear that MainWindow and MainWindowScrollbar are related. It's hard to tell that MainWindowScrollbar is a grouping that contains elements for MainWindow. It appears that LoginFrame,LoginScrollbar,Mainwindow,MainwindowScrollbar are all classes in the same classification.

class LoginFrame:
    def __init__(self):
       #somecode

class LoginScrollbar:
    def __init__(self):
       #somecode

class MainWindow:
    def __init__(self):
       #somecode

class MainWindowScrollbar:
    def __init__(self):
       #somecode

This is what I want, is this somehow possible without creating a seperate file for each frame of my program?

class LoginFrame:
    def __init__(self):
       #somecode

    class LoginScrollbar:
        def __init__(self):
           #somecode

    class LeftSideOfLogin:
        def __init__(self):
           #WidgetsForLeftSideOfLogin

class MainWindow:
    def __init__(self):
       #somecode

    class MainWindowScrollbar:
       def __init__(self):
           #somecode

    class MainWindowRightSide:
       def __init__(self):
           #WidgetsForRightSideOfMainWindow
Maks Ovnik
  • 65
  • 9
  • 2
    Organize your classes in modules and packages, not in nested classes. – Klaus D. Sep 13 '19 at 12:02
  • What are modules and packages? Do you mean create a file for every 'window' of the gui? For example a file for all the classes that encapsulate the login part of the gui? – Maks Ovnik Sep 13 '19 at 12:08
  • nested classes are practical if inner classes wont be accessible at any points. to store single class in one file explained here: https://stackoverflow.com/questions/1091756/are-multiple-classes-in-a-single-file-recommended – oetzi Sep 13 '19 at 12:12
  • In my experience, nested classes are more trouble than they are worth in most cases. – Bryan Oakley Sep 13 '19 at 13:03
  • So the only way to group the frames is to create seperate files? – Maks Ovnik Sep 13 '19 at 13:47
  • @MaksOvnik: I see no problem defining it like your second example. – stovfl Sep 13 '19 at 13:47

0 Answers0