How can I tweak this so that if xyz17
is selected from the Menu the function xyz17()
is run?
I'm aware of command = xyz17
but I'm not sure how to make that dynamic so that it depends on the menu selection.
from tkinter import *
def xyz17():
print('xyz17')
def abc27():
print('abc27')
def qwe90():
print('qwe90')
def uio19():
print('uio19')
def jkl09():
print('jkl09')
def zxc28():
print('zxc28')
class Menu(OptionMenu):
def __init__(self, master, status, *options):
self.var = StringVar(master)
self.var.set(status)
OptionMenu.__init__(self, master, self.var, *options)
def main():
TopFrame = Frame(root)
TopFrame.pack()
Menu1 = Menu(TopFrame, 'xyz', 'xyz17','abc27','qwe90')
Menu2 = Menu(TopFrame, 'uio', 'uio19','jkl09','zxc28')
Menu1.pack()
Menu2.pack()
root = Tk()
main()
root.mainloop()
Please note that the functions each priniting the value is just for an example, I would like the code to run the function itself. I'm aware of this:
class Menu(OptionMenu):
def __init__(self, master, status, *options):
self.var = StringVar(master)
self.var.set(status)
OptionMenu.__init__(self, master, self.var, *options, command=self.func)
def func(self,value):
print (value)
But, this isn't relevant to my scenario as it simply just gets the value and prints it, and I would like it to actually run the function itself.