Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 有没有办法计算单选按钮的累积值_Python_User Interface_Spyder_Cbt - Fatal编程技术网

Python 有没有办法计算单选按钮的累积值

Python 有没有办法计算单选按钮的累积值,python,user-interface,spyder,cbt,Python,User Interface,Spyder,Cbt,我正在编写一个基于CBT的测试程序,我已经完成了注册和登录阶段以及提问阶段,但我想在测试后点击finale submit按钮计算用户的总分,下面是我目前为止的代码 # -*- 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 """ f

我正在编写一个基于CBT的测试程序,我已经完成了注册和登录阶段以及提问阶段,但我想在测试后点击finale submit按钮计算用户的总分,下面是我目前为止的代码

# -*- 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()

你的问题格式不好。请修改标准规则:若你们有很多元素,那个么就把它们放在列表中。因此,您可以将其保留在列表中,并使用
val[0],val[1]
而不是
first
second
val1,val2
。然后您可以使用
for
-loop来处理列表中的元素。我会将带有答案的问题(和正确答案)保留在列表中,并使用
for
-loop来创建
标签和
单选按钮`和
StringVar
。然后我可以使用
for
-loop(和
zip()
)将
StringVar
中的值与列表中的正确答案进行比较。若要首先计算分数,您必须具有正确答案的列表或其他结构,以便将用户的答案与正确答案进行比较。您的问题格式不正确。请修改标准规则:若你们有很多元素,那个么就把它们放在列表中。因此,您可以将其保留在列表中,并使用
val[0],val[1]
而不是
first
second
val1,val2
。然后您可以使用
for
-loop来处理列表中的元素。我会将带有答案的问题(和正确答案)保留在列表中,并使用
for
-loop来创建
标签和
单选按钮`和
StringVar
。然后我可以使用
for
-loop(和
zip()
)将
StringVar
中的值与列表中的正确答案进行比较。要首先计算分数,您必须具有正确答案的列表或其他结构,以便您可以将用户的答案与正确答案进行比较。