2017-08-26 15 views
0
  detectionEnableCheckBoxFrame = tk.Frame(root) 
      detectionEnableCheckBoxVal = tk.IntVar() 
      detectionEnableCheckBoxVal.set(0) 
      detectionEnableCheckBox = tk.Checkbutton(detectionEnableCheckBoxFrame, 
                text='Enable Spike Detection', 
             variable=detectionEnableCheckBoxVal, 
           command=spikeDetectionEnableCallback) 
      detectionEnableCheckBox.grid(row=0, column=1, sticky=tk.W) 
      detectionEnableCheckBoxFrame.pack(fill=tk.X) 

我正在使用这段代码创建一个复选框。我想知道如何在单击复选框时实时将tk.IntVar()的值传递给回调。实时传递参数到TkInter中的复选框小部件的回调

回答

0
detectionEnableCheckBox = tk.Checkbutton(detectionEnableCheckBoxFrame, 
               text='Enable Spike Detection', 
            variable=detectionEnableCheckBoxVal, 
          command=lambda: spikeDetectionEnableCallback(arg)) 

使用lambda函数求解。