I'm trying to create a class that will take name and cascade as params and will add an item to the GUI's menu (using tkinter).
The code looks like this:
from tkinter import *
class new_menu_item:
def __init__(self, name, cascade):
self.name = name
self.cascade = cascade
menu = Menu(root)
root.config(menu=menu)
name = Menu(menu)
menu.add_cascade(label=cascade, menu=name)
name.add_command(label = name)
root = Tk()
newproject = new_menu_item('New Project', 'Edit')
oldproject = new_menu_item('Add employee', 'File')
root.mainloop()
I searched and found a way to use exec(name) instead of name for this part (Where I believe the problem is):
name = Menu(menu)
menu.add_cascade(label=cascade, menu=name)
But I also understood that exec() is unsafe and it's prefarable not to use it.
I'm not quit sure where i get stuck. But I can use some help.