menubar
has same name as its encolising class Menubar
15 if os.name == "nt":
16 self.menubar = CTkTitleMenu(root)
17 elif os.name == "posix":
18 self.menubar = CTkMenuBar(root) 19
20 # Title bar menus
21 self.file_menu = self.menubar.add_cascade("File")
menubar
has same name as its encolising class Menubar
13 def __init__(self, root):
14 self.root = root
15 if os.name == "nt":
16 self.menubar = CTkTitleMenu(root) 17 elif os.name == "posix":
18 self.menubar = CTkMenuBar(root)
19
menubar
has same name as its encolising class Menubar
13 def __init__(self, root, text_Area):
14 self.root = root
15 self.text_Area = text_Area
16 self.menubar = tk.Menu(self.root, background="grey", fg="white") 17 self.file_path_1 = None
18
19 # Defining menu options as menu objects
There is a class member with the same name (not considering the case difference) as its enclosing class.
This can cause confusion while reading the code later on keeping a track of what the field represents. It is strongly recommended to provide self-explanatory names so that someone who's reading the code doesn't have to spend time keeping a track of the variable/method names.
class Orange:
'''We mean, the fruit.'''
orange = "#FFA500"
# Other class implementations
def get_orange(self):
return abc
fruit = Orange()
render_to_frontend(fruit.orange) # Rendering a color, but one can get confused with the fruit
render_bg(fruit.get_orange) # Not clear that `get_orange` is returning a color
class Orange:
'''We mean, the fruit.'''
color = "#FFA500"
# Other class implementations
def get_color(self):
return abc
fruit = Orange()
render_to_frontend(fruit.color) # Evident that we are working with color
render_bg(fruit.get_color) # Evident that we are fetching the fruit's color