By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,536 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,536 IT Pros & Developers. It's quick & easy.

Tkinter- checkbutton

P: n/a
I want to have a checkbutton that when it is pushed will do a function
depending on if it was pushed before or not. Ei:


def check():
if (b.value==0):
However, I keep running into problems with reading the data. How do I
make this work? Thanks!

Nov 4 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
Ere, ignore the mis-capped Checkbutton and the missed master call in

Nov 4 '05 #2

P: n/a
In article <11**********************@g14g2000cwa.googlegroups .com>,
Tuvas <tu*****> wrote:
Ere, ignore the mis-capped Checkbutton and the missed master call in

You need to use a Tkinter variable (IntVar, StringVar or whatever),
associate it with the Checkbutton, and access it with the get() and
set() methods:

from Tkinter import *

root = Tk()

v = IntVar()

def do_stuff_here():
print "Value is zero"

def do_other_stuff_here():
print "Value is not zero"

def check():
if v.get() == 0:
elif v.get() == 1:
print "This is impossible, but it happened"

b = Checkbutton(root, text = 'Press Me', command = check, variable = v)
b.grid(row = 0, column = 0)

Jim Segrave (je*

Nov 4 '05 #3

P: n/a
That solved the problem. Thanks!

Nov 4 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.