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
#8
I used .place(x, y) to mimic your code. You should stop using .place() and use .pack() or .grid() instead.

Become a lazy typer. You should never type this many characters
        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"
When you can type this instead:
if any(cb.get() == 1 for cb in (chkbxitemCard, chkbxPicklist, chkbxQyickPick)):
    btnConvert["state"] = "normal"
else:
    btnConver["state"] = "disabled"
Not only is it less typing, it has less ability to hide errors and is easier to read. My way makes it obvious that the two possibilities are any checked or none checked. Your way I have to look at each of the comparisons and each of the logic operations

Don't use mixed case variable names unless forced. Python style guidelines associate special meanings with capital letters, Try to follow the style laid out in https://pep8.org/. Start using it early and it will become second nature. Once you are used to the style you'll find it really helps you read Python code.
Reply


Messages In This Thread
RE: Errors when trying to disable tkinter checkbutton - by deanhystad - Feb-17-2022, 10:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  an easy way to disable exception handling Skaperen 6 5,690 Jun-02-2019, 10:38 PM
Last Post: Gribouillis
  disable a block of code Skaperen 5 13,723 Aug-20-2018, 07:55 AM
Last Post: Skaperen
  gnureadline: disable temporarily? klaymen 1 2,595 May-08-2018, 11:16 AM
Last Post: Larz60+
  Checkbutton code not working ToddRyler 4 3,310 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