我在Tkinter上学了一个测验。
要回答一个问题,请选择一个单选按钮,但是当您在好的单选按钮上单击3次时,它将添加3点而不是1点...
有人可以帮助我吗?
谢谢!
我尝试了其他带有变量和值的方法,但是它在全局评分方面遇到了麻烦...
typedef struct pdi{
char *name;
char *descript;
char *schedule;
int id;
int popp;
int hotpoints;
struct pdi *prox;
}t_pdi;
typedef struct local{
int id;
char *name;
int popl;
struct local *prox;
}t_local;
typedef struct pessoa{
char *name;
char *address;
char *dob;
int phonenumber;
t_pdi *pdis;
t_local *local;
struct pessoa *prox;
}t_person;
void crialistapessoas(t_person *header_p, t_pdi *header_pdi, t_local *header_l){
FILE *fp;
t_person *node = header_p;
t_pdi *new1listpdi = create_headerPDI();
t_pdi *nodepdi = new1listpdi;
t_local *new1L;
t_pdi *new1PDI;
t_local *new1listlocals = create_headerL();
t_local *nodelocal = new1listlocals;
t_local *tempnodel;
t_pdi *tempnodepdi;
char *name = malloc(200*sizeof(char));
char *line = malloc(200*sizeof(char));
char *address = malloc(200*sizeof(char));
char *dob = malloc(200*sizeof(char));
int phonenumber;
int tempid,i, n;
fp = fopen("names.txt", "r");
fgets(line, 150, fp);
while(strcmp(line, "end")!=0){
name = strtok(line, "/");
address = strtok(NULL, "/");
dob = strtok(NULL, "/");
phonenumber = atoi(strtok(NULL, "/"));
new1listpdi = create_headerPDI();
new1listlocals = create_headerL();
nodepdi = new1listpdi;
nodelocal = new1listlocals;
n = atoi(strtok(NULL,"/"));
for(i=0;i<n;i++){
tempid = atoi(strtok(NULL,"/"));
printf("%d\n", tempid);
if(tempid>1000){
tempnodel = header_l;
while(tempnodel!=NULL && tempnodel->id != tempid){
tempnodel = tempnodel->next;
}
new1L = create_headerL();
new1L->id=tempid;
printf("%d\n", tempnodel->id);
new1L->name = strdup(tempnodel->name);
new1L->popl = tempnodel->popl;
new1L->next = nodelocal->next;
nodelocal->next = new1L;
}
else{
tempnodepdi = header_pdi;
while(tempnodepdi!=NULL && tempnodepdi->id != tempid){
tempnodepdi = tempnodepdi->next;
}
new1PDI = create_headerPDI();
new1PDI->id = tempid;
new1PDI->name = strdup(tempnodepdi->name);
new1PDI->descript = strdup(tempnodepdi->descript);
new1PDI->schedule = strdup(tempnodepdi->schedule);
new1PDI->hotpoints = tempnodepdi->hotpoints;
new1PDI->popp = tempnodepdi->popp;
new1PDI->next = nodepdi->next;
nodepdi->next = new1PDI;
}
}
insertpersonlist(header_p, name, address, dob, phonenumber, new1listlocals, new1listpdi);
fgets(line, 150, fp);
}
}
t_person *insertpersonlist(t_person *header_p, char *name, char *address, char *dob, int phonenumber, t_local *listlocals, t_pdi *listpdis){
t_person *new1;
t_person *node = header_p;
new1 = create_headerPerson();
if (new1== NULL)
return NULL;
while((node->next!=NULL)&&(strcmp(node->next->name, name)<0)){
node = node->next;
}
new1->name = strdup(name);
new1->address = strdup(address);
new1->dob = strdup(dob);
new1->phonenumber = phonenumber;
new1->pdis = listpdis;
new1->local = listlocals;
new1->next = node->next;
node->next = new1;
}
答案 0 :(得分:0)
可以有多种方法来完成您想要的工作,我建议您添加一个Button
,当按下该按钮时,它将检查答案并转到下一页,因此尽管我认为,也不会出现额外的分数问题您可能只有一页,并且有多个问题,所以这些想法可以用来解决您的问题。
我分配了一个列表,该列表将在功能ajouter1()
中存储正确的答案,并检查该答案是否已在列表(if ans not in score_list:
)中。还通过lambda: ajouter1("A1")
将参数传递给函数。 Here's how you pass parameters to the function in tkinter.
示例:
...
score_list = []
def ajouter1( ans ):
global score
if ans not in score_list:
score+=1
Score = "Bravo, Votre score est de: " + str(score) + "/10"
var_label.set(Score)
score_list.append(ans)
Q1 = Label(root, text="1) Comment se nomme le président français?", font='Helvetica 10 bold')
Q1.pack()
Q1A = Radiobutton(root, text="Nicolas Sarkozy", value=2, variable=rep1)
Q1A.pack()
Q1B = Radiobutton(root, text="Emmanuel Macron", value=1, variable=rep1, command=lambda: ajouter1('A1'))
Q1B.pack()
Q1C = Radiobutton(root, text="François Hollande", value= 3, variable=rep1)
Q1C.pack()
...
我可以想到的另一种方法是,当用户单击问题的任何Radiobutton
时,这些Radiobutton
的状态就会被禁用,因此用户不会作弊。
类似的东西:
def ajouter1( ans ):
global score
if ans:
score+=1
Score = "Bravo, Votre score est de: " + str(score) + "/10"
var_label.set(Score)
Q1A['state'] = 'disabled'
Q1B['state'] = 'disabled'
Q1C['state'] = 'disabled'
Q1 = Label(root, text="1) Comment se nomme le président français?", font='Helvetica 10 bold')
Q1.pack()
Q1A = Radiobutton(root, text="Nicolas Sarkozy", value=2, variable=rep1, command=lambda: ajouter1(False))
Q1A.pack()
Q1B = Radiobutton(root, text="Emmanuel Macron", value=1, variable=rep1, command=lambda: ajouter1(True))
Q1B.pack()
Q1C = Radiobutton(root, text="François Hollande", value= 3, variable=rep1, command=lambda: ajouter1(False))
Q1C.pack()