Hi,
I have created a checkbutton within a dialog box. But, I am not able to capture the value of the checkbutton. The value always seems to be 0 whether checked or not.

class MyDialog:
    
    def __init__(self,parent):
        self.Frame1= Tix.Frame(parent)
        self.Frame1.pack(side=Tix.LEFT, fill=Tix.BOTH)
        
        self.enabled = Tix.IntVar()
        
        self.checkbutton = Tix.Checkbutton(self.Frame1,text = "Enable Email Option", variable=self.enabled,command=self.OnCheckBoxClick)
        self.checkbutton.pack(side=Tix.TOP)
        
            
    def OnCheckBoxClick(self):
        iTemp = self.enabled.get()
        print "iTemp %s"%iTemp

Can you tell me whats wrong with the code?

Thanks!

Recommended Answers

All 2 Replies

The following works for me. Check the rest of your code that is not posted for differences.

from Tkinter import *
class MyDialog:
 
    def __init__(self,parent):
        self.Frame1= Frame(parent)
        self.Frame1.pack()
 
        self.enabled = IntVar()
 
        self.checkbutton = Checkbutton(self.Frame1,text = "Enable Email Option", variable=self.enabled,command=self.OnCheckBoxClick)
        self.checkbutton.pack()
 
 
    def OnCheckBoxClick(self):
        iTemp = self.enabled.get()
        print "iTemp %s"%iTemp

root=Tk()
M=MyDialog(root)
root.mainloop()
import Tix

class MyDialog:
 
    def __init__(self,parent):
        self.Frame1= Tix.Frame(parent)
        self.Frame1.pack()
 
        self.enabled = Tix.IntVar()
 
        self.checkbutton = Tix.Checkbutton(self.Frame1,text = "Enable Email Option", variable=self.enabled,command=self.OnCheckBoxClick)
        self.checkbutton.pack()
 
 
    def OnCheckBoxClick(self):
        iTemp = self.enabled.get()
        print "iTemp %s"%iTemp

root=Tix.Tk()
M=MyDialog(root)
root.mainloop()

This code works perfectly on IDLE. But, the exact same code isn't working on WingIDE for me :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.