1

目前正在使用记事本应用程序并遇到 OptionMenu 小部件的问题。

self.fileOptionMenu = OptionMenu(self.master, self.var, *self.fileList, command=self.openFileCurrentDir)
self.fileOptionMenu.pack()

def openFileCurrentDir(self):
    print("inside openFileCurrentDir()")

更改选择后该openFileCurrentDir()功能永远不会运行

4

1 回答 1

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())
于 2019-03-23T09:33:46.727 回答