我试图在循环中创建选项菜单,选项菜单的数量取决于一个变量。所以我试图在我的代码中使用 exec 。我使用以下内容传递 'i' 的值以连接到正在更改值的变量。但是一旦我调用跟踪,我在“选项”菜单中选择的选项就不会在“选项”菜单框中更新。如果我不调用跟踪功能,它会在显示中更新。trackProcessMenu 是回调函数。请让我知道,我在哪里犯了错误。添加我的代码:for i in range(0,numOfLibFiles): exec('self.processOptionMenuVar_%d = StringVar()'%i) process_menu = ("ff","ss","tt","fff","sss","ttt") exec('self.processOptionMenu_%d = OptionMenu(self, self.processOptionMenuVar_%d, *process_menu )'%(i,i)) exec('self.processOptionMenu_%d.config(indicatoron=0,compound=RIGHT,image= self.downArrowImage, anchor = CENTER , direction = RIGHT)'%i) exec('self.processOptionMenuVar_%d.set("--")'%i) exec('self.processOptionMenu_%d.grid(row = i, column =1, sticky = N ,padx=30, pady =7 )'%i)def trackProcessMenu(self,*args): i = args[0] exec('process = self.processOptionMenuVar_%d.get()'%i)
添加回答
举报
0/150
提交
取消