两个按钮都在csv问题中打开同一表?

问题描述 投票:0回答:2

这是两个按钮

second_year_icon = tk.PhotoImage(file = r"D:\Academy Management Application\Icons\2nd_year_icon.png")
global second_year_btn
second_year_btn = tk.Button(label_frame, font=LARGE_FONT, image=second_year_icon,
                      border=0 ,command=lambda : controller.show_frame(second_year) )
second_year_btn.grid(row=0 , column =0, padx=(10,10) , pady=(10,0), sticky=tk.E)


first_year_icon=tk.PhotoImage(file = r"D:\Academy Management 
Application\Icons\1st_year_icon.png")

        global first_year_btn
        first_year_btn = tk.Button(label_frame, font=LARGE_FONT, image=first_year_icon
                            , command=lambda : controller.show_frame(second_year), border=0 )
        first_year_btn.grid(row=0 , column =1, padx=(10,10) , pady=(10,0), sticky=tk.E)

现在,如果单击first_year_btn,当我单击second_year_btn时,它也会显示相同的数据。我知道我犯了一些愚蠢的错误,但是哪一个都不是。我非常紧张。谁能帮我吗?

reader = DictReader(f, delimiter=',')
    for row in reader:
        if first_year_btn:
            if row['Class Name'] == '09th':
                registration_no= row['Registration No']
                student_name = row['Student Name']
                f_name = row['Father Name']
                gender = row['Gender']
                class_name =row['Class Name']
                class_session =row['Class Session']
                admission_date =row['Admission Date']
                monthly_fee = row['Monthly Fee']
                dues_payment=row['Dues']
                tree.insert("", 0, values=(registration_no, student_name, f_name,gender,class_name,class_session,admission_date,monthly_fee,dues_payment))
        elif  second_year_btn :

            if row['Class Name'] == 'Second Year':
                registration_no = row['Registration No']
                student_name = row['Student Name']
                f_name = row['Father Name']
                gender = row['Gender']
                class_name = row['Class Name']
                class_session = row['Class Session']
                admission_date = row['Admission Date']
                monthly_fee = row['Monthly Fee']
                dues_payment = row['Dues']
                tree.insert("", 0, values=(
                registration_no, student_name, f_name, gender, class_name, class_session, admission_date,
                monthly_fee, dues_payment))
python python-3.x csv tkinter tk
2个回答
0
投票
按照这种结构,MainFrameClass是您的旧类,它来自Library或为您创建旧框架。它有一些正在该框架内使用的变量。您的任务是创建新类,将旧类继承为新类。创建一个新方法,通过该方法,您只能更改要在框架内更改的那些变量。

0
投票
以下是基于您发布的代码的简单示例:
© www.soinside.com 2019 - 2024. All rights reserved.