Everything is good if I'm in root window but I can't set variable in newly created window. It always gives me default empty checkbox. I have one more question and that is how can I save chosen options so when I open options(settings) window again same options will be checked or unchecked.
from Tkinter import *
# TKINTER CODE ######################################################################## #
root = Tk()
root.title('window')
Label(text='input').grid(row=0, sticky=W, padx=10, pady=10)
entry = Entry(root, width=50)
entry.grid(row=1, sticky=W+E, padx=10, pady=10)
entry.insert(0, "input")
text = Text(root, width=80, state=DISABLED)
text.grid(row=2, column=0, sticky=W, padx=0, pady=0)
scrollbar = Scrollbar(root)
scrollbar.grid(row=2, column=1, sticky=N+S+W+E)
scrollbar.config(command=text.yview)
# Settings window
def open_settings():
settings_win = Toplevel(root)
settings_win.title('Settings')
settings_win.geometry('300x300')
settings_win.resizable(width=FALSE, height=FALSE)
settings_win_button.config(state='disable')
def close_settings_window():
settings_win.destroy()
settings_win_button.config(state='normal')
# options to choose from
option_var1 = IntVar()
# Make default position to be checked
option_var1.set(1)
option_var2 = IntVar()
option1 = Checkbutton(settings_win, text="option1", variable=option_var1)
option1.grid(row=0, column=0)
option2 = Checkbutton(settings_win, text="option2", variable=option_var2)
option2.grid(row=1, column=0)
quit_settings_button = Button(settings_win, text='Save', command=close_settings_window)
quit_settings_button.grid(row=10, column=0)
settings_win.protocol("WM_DELETE_WINDOW", close_settings_window)
settings_win_button = Button(root, text='Options', command=open_settings)
settings_win_button.grid(row=0, column=0)
# Menu Bar ############################################################################ #
menubar = Menu(root)
# create a pulldown menu, and add it to the menu bar
filemenu = Menu(menubar, tearoff=0)
# filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="File", menu=filemenu)
helpmenu = Menu(menubar, tearoff=0)
menubar.add_cascade(label="Help", menu=helpmenu)
# display the menu
root.config(menu=menubar)
# End ################################################################################# #
root.mainloop()
I want option1 in newly created window to be checked.
Aucun commentaire:
Enregistrer un commentaire