duyanhhz
duyanhhz

Reputation: 65

How to run command if checkbox is ticked

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
)

Upvotes: 1

Views: 338

Answers (1)

JRiggles
JRiggles

Reputation: 6760

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
)

Upvotes: 1

Related Questions