Right off the bat here is my code so far (please ignore the variable names. I am still learning how to use Python):
root = Tk()
testvariable = 0
bruh = 0
test = Checkbutton(root, variable = testvariable, )
test.pack()
test1 = Entry(root,textvariable = bruh, text = "0", width = 4)
test1.pack()
root.mainloop()
I notice that when I select the Checkbutton to turn it off or on, the Entry widget automatically changes its value to whatever the Checkbutton's value is. Is there a way to prevent this?
When setting variables in tkinter make sure to use the built-in types (https://docs.python.org/3/library/tkinter.html#coupling-widget-variables).
For the Entry widget you can directly use the get method to assign its value to a variable. As for the Checkbutton widget, make sure to assign it an "IntVar" type to correctly deal with its value passing. I've demonstrated how to do both of the above in the code below.
import tkinter as tk
root = tk.Tk()
checkbox_var = tk.IntVar()
testvariable = 0
bruh = 0
test = tk.Checkbutton(root, variable=checkbox_var)
test.pack()
test1 = tk.Entry(root)
test1.pack()
def testOutput():
testvariable = checkbox_var.get()
bruh = test1.get()
print("Checkbox is", testvariable)
print("Entry is", bruh)
button = tk.Button(root, text="Test Button", command=testOutput)
button.pack()
root.mainloop()