有没有一种方法可以计算单选按钮的累计值

时间:2019-12-23 19:05:21

标签: python user-interface spyder cbt

我正在编写一个基于CBT的测试程序,我已经完成了注册和登录阶段以及问题的阶段,但是我想在测试后单击“结局提交”按钮来计算用户的总分到目前为止我的代码是

# -*- coding: utf-8 -*-
"""
Created on Mon Dec 23 16:05:02 2019

@author: Emma
"""

# -*- coding: utf-8 -*-
"""
Created on Thu Dec 19 16:19:18 2019

@author: Emma
"""
from tkinter import *
from tkinter.messagebox import *

class Cbt:
    def __init__(self):

        self.window = Tk()
        self.window.title('CBT')
        self.fm = Frame(self.window)
        self.fm.pack(side = TOP, expand = YES, fill = BOTH)
        self.fm.grid_propagate(0)
        self.text1=StringVar()
        self.text2=StringVar()
        self.registration = Label(self.fm, text = "Registration Page", font=('arial',30,'bold') ).pack()
        self.name = Label(self.fm, text = "Username",font=('arial',20) ).pack()
        self.nametext = Entry(self.fm, width = 10,bd=20,textvariable = self.text1, insertwidth=4, justify='left', font=('arial',20,'bold')).pack()
        self.password = Label(self.fm, text = "Password",font=('arial',20) ).pack()
        self.passwordtext = Entry(self.fm, width = 10,bd=20,textvariable = self.text2, insertwidth=4, justify='left', font=('arial',20,'bold')).pack()
        self.regsubmit = Button(self.fm, width = 10, text = "Submit", command = self.reg).pack()
        self.roottext = ''
        self.roottext2 = ''
        self.roottext3 = ''
        self.roottext4 = ''

        self.window.mainloop()

    def login(self):
        self.log = Frame(self.window)
        self.log.pack(side = TOP, expand = YES, fill = BOTH)
        self.log.grid_propagate(0)
        self.text3=StringVar()
        self.text4=StringVar()         
        self.login = Label(self.log, text = "Login Page", font=('arial',30,'bold') ).pack()
        self.name2 = Label(self.log, text = "Username",font=('arial',20) ).pack()
        self.nametext2 = Entry(self.log, width = 10,bd=20,textvariable = self.text3, insertwidth=4, justify='left', font=('arial',20,'bold')).pack()
        self.password2 = Label(self.log, text = "Password",font=('arial',20) ).pack()
        self.passwordtext2 = Entry(self.log, width = 10,bd=20,textvariable = self.text4, insertwidth=4, justify='left', font=('arial',20,'bold')).pack()
        self.logsubmit = Button(self.log, width = 10, text = "Submit", command = self.loginfunc).pack()

    def reg(self):
        self.roottext = self.text1.get()
        self.roottext2 = self.text2.get()
        if self.roottext != '' and self.roottext2 != '':
            showinfo("Success","Registration Successful")
            self.fm.destroy()
            self.login()

        else:
            showinfo("Failed","Registration Failed")

    def loginfunc(self):
        self.roottext3 = self.text3.get()
        self.roottext4 = self.text4.get()
        if self.roottext3 == self.roottext and self.roottext4 == self.roottext2:
            showinfo("Success", "Login Successful")
            self.log.destroy()
            self.question()
        else:
            showinfo("Failed", "Login Failed")

    def onClick(self):
        pass

    '''def cal():
        val1 = first.get()
        val2 = second.get()

        val3 = third.get()
        val4 = fourth.get()
        val5 = fifth.get()
        val6 = sixth.get()
        val7 = seventh.get()
        val8 = eight.get()
        val9 = ninth.get()
        val10 = tenth.get()'''

    def question(self):

        def cal(self):
            self.val1 = first.get()
            self.val2 = second.get()
            self.val3 = third.get()
            self.val4 = fourth.get()
            self.val5 = fifth.get()
            self.val6 = sixth.get()
            self.val7 = seventh.get()
            self.val8 = eight.get()
            self.val9 = ninth.get()
            self.val10 = tenth.get()

        self.fm = Frame(self.window)
        self.fm.pack(side = TOP, expand = YES, fill = BOTH)
        self.fm.grid_propagate(0)

        #confm, congroup=StringVar(),StringVar()
        first = StringVar()
        second = StringVar()
        third = StringVar()
        fourth = StringVar()
        fifth = StringVar()
        sixth = StringVar()
        seventh = StringVar()
        eight = StringVar()
        ninth = StringVar()
        tenth = StringVar()

        Label(self.fm, text = 'Where is the headquarter of UN situated?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = first, text = 'A. Geneva', value = 'a', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = first, text = 'B. Hague', value = 'b', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = first, text = 'C. New York', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = first, text = 'D. Addis Ababa', value = 'd', command = self.onClick, tristatevalue = 0).pack()


        Label(self.fm, text = 'The President of France is?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = second, text = 'A. Emmanuel Macron', value = 'a', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = second, text = 'B. Donald Trump', value = 'b',command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = second, text = 'C. Francois Hollande', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = second, text = 'D. Laurent Gbagbo', value = 'd',command = self.onClick, tristatevalue = 0).pack()


        Label(self.fm, text = 'The full meaning of SQL is?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = third, text = 'A. Structured Query Language', value = 'a', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = third, text = 'B. Structural Query Language', value = 'b',command = self.onClick,  tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = third, text = 'C. Structure Query Language', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = third, text = 'D. Structured Query Lambda', value = 'd',command = self.onClick, tristatevalue = 0).pack()

        Label(self.fm, text = 'An example of a developing country is?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = fourth, text = 'A. India', value = 'a', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = fourth, text = 'B. New Zealand', value = 'b', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = fourth, text = 'C. Croatia', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = fourth, text = 'D. Switzerland', value = 'd', command = self.onClick, tristatevalue = 0).pack()

        Label(self.fm, text = 'The most populated country in the world is?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = fifth, text = 'A. Phillipines', value = 'a', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = fifth, text = 'B. China', value = 'b', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = fifth, text = 'C. India', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = fifth, text = 'D. Brazil', value = 'd', command = self.onClick, tristatevalue = 0).pack()


        Label(self.fm, text = 'The capital of France is?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = sixth, text = 'A. Monaco', value = 'a',command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = sixth, text = 'B. Paris', value = 'b', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = sixth, text = 'C. Lyon', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = sixth, text = 'D. Marseille', value = 'd', command = self.onClick, tristatevalue = 0).pack()

        Label(self.fm, text = 'The capital of Ethiopa is?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = seventh, text = 'A. Ethiope', value = 'a', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = seventh, text = 'B. Addis Ababa', value = 'b', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = seventh, text = 'C. Eritrea', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = seventh, text = 'D. Botswana', value = 'd', command = self.onClick, tristatevalue = 0).pack()


        Label(self.fm, text = 'The richest man on earth is?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = eight, text = 'A. Bill Gates', value = 'a', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = eight, text = 'B. Jeff Bezos', value = 'b', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = eight, text = 'C. Jack Ma', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = eight, text = 'D. Warren Buffet', value = 'd', command = self.onClick, tristatevalue = 0).pack()

        Label(self.fm, text = 'The president of FIFA is?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = ninth, text = 'A. Giovanni Infantino', value = 'a', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = ninth, text = 'B. Sepp Blatter', value = 'b', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = ninth, text = 'C. Michel Platini', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = ninth, text = 'D. Isa Hayatou', value = 'd', command = self.onClick, tristatevalue = 0).pack()

        Label(self.fm, text = 'The most powerful president/Prime Minister in the world is?', font=('arial',20,'bold')).pack()
        Radiobutton(self.fm, variable = tenth, text = 'A. Muhammadu Buhari', value = 'a', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = tenth, text = 'B. Donald Trump', value = 'b', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = tenth, text = 'C. Vladmir Putin', value = 'c', command = self.onClick, tristatevalue = 0).pack()
        Radiobutton(self.fm, variable = tenth, text = 'D. Benjamin Netanyahu', value = 'd', command = self.onClick, tristatevalue = 0).pack()

        finale = Button(self.fm, width = 10, text = "Submit", command = self.cal).pack()


cb = Cbt()

0 个答案:

没有答案