我正在创建一个tkinter应用程序,尝试从不同帧中的多个复选框中获取值。当我单击一帧中的复选框时,它也会在另一帧中进行检查。我想知道如何从不同的框架中访问复选框值。
当试图检查复选框(frame1中的Tb1)时,它也在检入(NLframe中的NLTb1)。我想知道如何分别访问这两个复选框值。
from tkinter import *
def create_widgets_in_first_frame():
task_type=Button(main_frame,text='Task Type',command=call_second_frame_on_top).grid(row=6,column=0,sticky=W)
Network_Location=Button(main_frame,text='Network Location',command=call_third_frame_on_top).grid(row=7,column=0,sticky=W)
def create_widgets_in_second_frame():
T1=Label(frame1,text="Verify and ensure there is no duplicate entries present in task type",bg='Light blue')
T1.grid(row=3,columnspan=2,sticky=W)
#creating checkbutton
Tb1=Checkbutton(frame1,text='Pass',font=('Times New Roman',14),bg='Green')
Tb1.grid(row=3,column=4,padx=6)
#creating checkbuttonx
r2=Checkbutton(frame1,text='Fail',font=('Times New Roman',14),bg='red')
r2.grid(row=3,column=5,padx=6)
#creating Run button
b1=Button(frame1,text='Run').grid(row=3,column=6,padx=6)
button=Button(frame1,text='Go to Main page',command=call_first_frame_on_top)
button.grid(row=20,column=0,padx=6,sticky=W)
def create_widgets_in_third_frame():
NL1=Label(NLframe,text="Verify the migrated Network location in NGMSS and ensure all the mandatory information's are migrated along with it",bg='Light blue')
NL1.grid(row=3,columnspan=2,sticky=W)
#creating checkbutton
NLTb1=Checkbutton(NLframe,text='Pass',font=('Times New Roman',14),bg='Green')
NLTb1.grid(row=3,column=4,padx=6)
#creating checkbuttonx
nbr2=Checkbutton(NLframe,text='Fail',font=('Times New Roman',14),bg='red')
nbr2.grid(row=3,column=5,padx=6)
#creating Run button
nlb1=Button(NLframe,text='Run').grid(row=3,column=8)
button=Button(NLframe,text='Go to Main page',command= call_first_frame_on_top)
button.grid(row=20,column=0,padx=6,sticky=W)
def call_first_frame_on_top():
frame1.grid_forget()
NLframe.grid_forget()
main_frame.grid(row=0,column=0,sticky=W+E+N+S)
def call_second_frame_on_top():
NLframe.grid_forget()
main_frame.grid_forget()
frame1.grid(row=0,column=0,sticky=W+N+E+S)
def call_third_frame_on_top():
NLframe.grid(row=0,column=0,sticky=W+N+E+S)
frame1.grid_forget()
main_frame.grid_forget()
def quit_program():
root_window.destroy()
def raise_frame():
main_frame.tkraise()
root= Tk()
main_frame=Frame(root,height=30,width=500,borderwidth=10,bg='Powder Blue',highlightthickness=10,highlightcolor="red")
main_frame.grid(row=0,column=0,sticky=W+E+N+S)
frame1=Frame(root,height=30,width=500,borderwidth=10,bg='Powder Blue',highlightthickness=10,highlightcolor="red")
frame1.grid(row=0,column=0,sticky=W+N+E+S)
NLframe=Frame(root,height=30,width=500,borderwidth=10,bg='Powder Blue',highlightthickness=5,highlightcolor="red")
NLframe.grid(row=1,column=0,sticky=W+N+E+S)
create_widgets_in_third_frame()
create_widgets_in_second_frame()
create_widgets_in_first_frame()
frame1.grid_forget()
NLframe.grid_forget()
raise_frame()
root.mainloop()
`