I've written this code to get the variable from a checkbutton across two separate windows, as shown below...
However, the checkbutton variable doesn't update, and every time the checkbutton is clicked, the program will always output 'variable is 0.'
from tkinter import *
from tkinter import ttk
e9 = None # extras checkbox
checke9 = 0 # variable to check value of extras checkbox
def checkcb() :
global checke9
print("variable is " + str(checke9.get()))
def customer_window() :
# assign global variables
global checke9
global callroot
global e9
# assign variable for the extras checkbox
checke9 = IntVar()
checke9.set(0)
# close previous window
callroot.destroy()
# set customer info
customer = Tk()
customer.resizable(width=False, height=False)
customer.configure(bg = "#c8ebf7")
# create extra choices
Label(customer, text="Checkbox: ", anchor="e", font="Corbel 12 italic", width="12", bg="#c8ebf7").grid(row=9)
e9 = Checkbutton(customer, text="Click here...", variable=checke9, offvalue=0, onvalue=1, font="Corbel 12", bg="#c8ebf7", command=checkcb)
e9.grid(row=9, column=1, sticky=W)
customer.mainloop()
# define function to open the main (root) window
def root_window() :
# set root info
root = Tk()
root.resizable(width=False, height=False)
root.configure(bg = "#c8ebf7")
global callroot
callroot = root
# create title label
Button(root, text="Open Window...", font="Corbel 14 bold", width=20, command=customer_window).grid(row=1, column=0, pady=30)
Button(root, text="Close", font="Corbel 8", width=10, command=root.destroy).grid(row=3, column=0, pady=5)
root.mainloop()
# start program
root_window()
Can you help? Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire