Python Forum
Errors when trying to disable tkinter checkbutton
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Errors when trying to disable tkinter checkbutton
#1
    Hello,

    I am having an issue disabling a tkinter checkbutton. I am able to get the value, but when trying to disable it I keep getting the below errors. I have tried StringVar instead of IntVar, but get similar errors. Not sure what am doing wrong. Any help is greatly appreciated!

    

####################
class checkboxes():
####################

    #===================
    def __init__(self, master):
    #
    #===================

        self.master = master



    #===================
    def addCheckBox(self, txt, w, h, x, y, fnt, clr, cmd):
    #
    #===================

        self.var1 = tk.IntVar()

        self.chkbx= Checkbutton(self.master, width=w, height=h, text=txt, variable=self.var1, onvalue=1, offvalue=0, font=fnt, bg=clr, command=cmd)
        self.chkbx.config(state="normal") #this works here only
        self.chkbx.place(x=x, y=y)
        return self.var1

    #===================
    def chkbxClick(self):
    #
    #===================

        print (self)
        print(self, chkbxItemCard.get())

        if chkbxItemCard.get() == 1 or chkbxPicklist.get() == 1 or chkbxQuickPick.get() == 1:
            btnConvert["state"] = "normal"

        if chkbxItemCard.get() == 0 and chkbxPicklist.get() == 0 and chkbxQuickPick.get() == 0:
            btnConvert["state"] = "disabled"

    #      chkbxItemCard.config(state="disabled") #AttributeError: 'IntVar' object has no attribute 'config'
    #      chkbxItemCard["state"] = "disabled" #TypeError: 'IntVar' object does not support item assignment



        chkbxItemCard = checkboxes.addCheckBox(master, 'TestItemCard', 30, 1, 45, 470, 'Aerial, 15', 'AntiqueWhite1', lambda: checkboxes.chkbxClick("chkItemCard")) #self, txt, w, h, x, y, fnt, clr, cmd
Reply


Messages In This Thread
Errors when trying to disable tkinter checkbutton - by rrick_88 - Feb-16-2022, 02:42 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  an easy way to disable exception handling Skaperen 6 5,722 Jun-02-2019, 10:38 PM
Last Post: Gribouillis
  disable a block of code Skaperen 5 13,814 Aug-20-2018, 07:55 AM
Last Post: Skaperen
  gnureadline: disable temporarily? klaymen 1 2,607 May-08-2018, 11:16 AM
Last Post: Larz60+
  Checkbutton code not working ToddRyler 4 3,321 Dec-24-2017, 12:34 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020