当前正在使用记事本应用程序,并且OptionMenu小部件存在问题。
self.fileOptionMenu = OptionMenu(self.master, self.var, *self.fileList, command=self.openFileCurrentDir)
self.fileOptionMenu.pack()
def openFileCurrentDir(self):
print("inside openFileCurrentDir()")
更改选择后永远不会运行openFileCurrentDir()
函数
答案 0 :(得分:2)
您可以在trace
上使用StringVar
方法。
def __init__(self,master):
self.master = master
self.var = StringVar()
self.var.trace("w", self.openFileCurrentDir)
l = ["A","B","C","D"]
self.fileOptionMenu = OptionMenu(self.master, self.var, *l)
self.fileOptionMenu.pack()
def openFileCurrentDir(self,*args):
print("inside openFileCurrentDir()"+self.var.get())