samedi 16 février 2019

How can I check Checkbutton value?

I have a couple of checkboxes - created using dict and for loop. Everything seems to work just fine until I hit the "check" button. It seems that I don't know how to check the Checkbutton current value.

import random
from tkinter import *


def rolldice(dice):
    return random.randrange(1, dice, 1)


root = Tk()
root.wm_title("Dices")
dices = [4, 6, 8, 10, 12, 20]
check_box = {item: BooleanVar() for item in Dices}


def checkDices():
    if C == True:
        rolldice(item in Dices)
    else:
        print("end")


for item in Dices:
    C = Checkbutton(root, text=item, variable=check_box[item], anchor=W, height=1, width=40)
    C.pack()

B1 = Button(root, text="Check", command=checkDices)
B1.pack()


root.mainloop()




Aucun commentaire:

Enregistrer un commentaire