1

I want to execute an extra function in the command if the checkbox is ticked, and if it is not ticked, then i don't want my program to execute it, how can i do that?

I.e, I want to execute CreateWallet Function if the checkbox is ticked, however, I don't want to disable the addchrome() one!

Thanks in advance!

from tkinter import *
from lib.SUI import WizardLand, RequestTokens, ExampleNFT, addchrome, CreateWallet

root = Tk()
root.title('Tool')
root.state('zoomed')

button_quit = Button(
        root,
        text="Exit Program",
        command=root.quit
)


button1 = Button(
        root,
        text="Start",
        command=lambda: [
                addchrome(),
                CreateWallet()]
)


#Options
var = IntVar()
opt1 = Checkbutton(
        root,
        text = "Create Wallet",
        variable=var
)

1
  • First of all, you need to abandon this ugly trick of using a lambda with a list to execute multiple functions. If the Button's command= referred to an ordinary function, defined with def, then you could trivially use if statements (and all of the other power of the Python language) to make things happen conditionally. Commented Nov 14, 2022 at 14:55

1 Answer 1

1

Define a wrapper function that can be called by button1 to execute addChrome, and conditionally execute CreateWallet

def on_button_press():
    is_checked = var.get()
    addChrome()
    if is_checked:
        CreateWallet()


button1 = Button(
    root,
    text="Start",
    command=on_button_press  # call that function
)

#Options
var = IntVar()
opt1 = Checkbutton(
    root,
    text="Create Wallet",
    variable=var
)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.