I'm facing a problem that whenever I check/uncheck the checkbox, I only get this output: "value is 0". Below is a simple script I'm using:
import tkinter as tk
from tkinter import *
root = tk.Tk()
root.title("Main app")
#the main frame is empty
#another tab within the software
def agent_module():
root1 = tk.Tk()
root1.title("New Tab")
var1 = tk.IntVar()
#function executed when checkbox is clicked
def function():
if var1.get() == 1:
print("value is 1")
elif var1.get() == 0:
print("value is 0")
#widget (this case checkbox only) in the tab
checkbox = tk.Checkbutton(root1, text="Press me", variable=var1, command=function)
checkbox.grid()
#menu bar configuration
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Software", command=agent_module)
menubar.add_cascade(label="Main", menu=filemenu)
#necessary stuff for the app
root.config(menu=menubar)
root.mainloop()
My goal is that I want to see the output when I check/uncheck the Checkbox. However, my only output is "value is 0" even if the checkbox is checked.