Menu

Checkbutton starts with a gray background

Anonymous
2019-08-17
2019-08-17
  • Anonymous

    Anonymous - 2019-08-17

    I have attached two images, one before and one after.
    What happens is: I have a lot of checkbuttons on a screen. When I run the program, the checkbuttons are not white, but they always start gray. If I click them, they behave normally, being white squared confirmed or white square unconfirmed. I don't know why the white square turns gray when I run the program. I would like to have it always as a normal white square, as I see it on the PAGE constructor screen.

    Why does it change when I run the program? How can I avoid that?

     
  • Greg Walters

    Greg Walters - 2019-08-17

    When you use a checkbutton or a series of radio buttons, you should "initialize" them with a value before the program starts.
    I usually do this in the 'init' function if there are only a few of them. Otherwise I create a function that I call something like 'def setup_buttons():' that handles this called from the init function.

    Let's say that you have 3 checkbuttons that you want to set. We'll demonstrate using the setup function. Further, assume that the checkbuttons have the variable attributes set to chk1, chk2 and chk3.

    def setup_buttons():
        chk1.set('0')  # set to empty or not checked
        chk2.set('1')  # set to checked
        chk3.set('0')  # set to not checked
    
    def init():
        #This function is provided by Page and is the last thing that is run before the form is shown to the user.
        global w, top_level, root
        w = gui
        top_level = top
        root = top
        # Your code here....
        setup_buttons()
        ...
    

    I hope this helps.

    Greg

     
  • Anonymous

    Anonymous - 2019-08-17

    Thanks, it is working as intended now!

     
  • Greg Walters

    Greg Walters - 2019-08-17

    I'm glad I was able to help.

    Greg

     

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.