用另一个替换一个功能

问题描述

我试图用下面的compare()函数替换Tkinter块中的test()函数。 我已经尝试了很长时间,但是我做不到。 为了总结上下文,我有我的程序(我的比较函数),我复制了某人的Tkinter部分。这个已经具有比较功能,我只是想插入我的基本比较功能,而不是在Tkinter部分中插入一个比较功能,但是我做不到。 预先感谢

from tkinter import *

root = Tk()
root.geometry('372x362')
root.configure(bg="pink")
Label(root,text='Homme',bg="pink",fg="black").grid(row=0,column=1)
Label(root,text='Femme',column=3)
Male = Entry(root)
Male.grid(row=1,text='&',fg="black").grid(row=1,column=2)
Female = Entry(root)
Female.grid(row=1,column=3)

class Candidat: #Subject class (characteristics)
    def __init__(self,genre,humour,physique,intelligence,projet):
        self.genre=genre
        self.humour=humour
        self.physique=physique
        self.intelligence=intelligence
        self.projet=projet

def test():

    MaleEntry = Male.get()
    FemaleEntry = Female.get()
    if MaleEntry == FemaleEntry:
        Label(root,text='0% compatibility',bg="red",fg="white").grid(row=3,column=2)

    else:
        Label(root,text='100% compatibility',bg="green",column=2)

Button(root,text='Test de Compatibilité',command=test,bg="purple",fg="white",bd=4).grid(row=2,column=2)

root.mainloop()


#-----------------------------------------------------------------------------------------------------#
    #Second part (I know that several conditions are missing but it is to keep the code as small as possible.)

def compare(Test1,Test2):

    if Test1.humour==Test2.humour and Test1.physique==Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet==Test2.projet:
        Label(root,text='Match Parfait 100%',fg="white").grid(row=4,column=2)
    elif Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
        Label(root,text='Mauvais Match 0%',column=2)
#Match à 75% :

    if Test1.humour!=Test2.humour and Test1.physique==Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet==Test2.projet:
        Label(root,text='Mauvais Match 75%',text='Mauvais Match 1',column=2)

    if Test1.humour==Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet==Test2.projet:
        Label(root,text='Mauvais Match 2',column=2)

    if Test1.humour==Test2.humour and Test1.physique==Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet==Test2.projet:
        Label(root,text='Mauvais Match 3',column=2)

    if Test1.humour==Test2.humour and Test1.physique==Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet!=Test2.projet:
        Label(root,text='Mauvais Match 4',column=2)

#Match à 50% :

    if Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet==Test2.projet:
        Label(root,text='Mauvais Match 50%',text='Mauvais Match 01',column=2)

    if Test1.humour!=Test2.humour and Test1.physique==Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet==Test2.projet:
        Label(root,text='Mauvais Match 02',column=2)

    if Test1.humour!=Test2.humour and Test1.physique==Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet!=Test2.projet:
        Label(root,text='Mauvais Match 03',column=2)

    if Test1.humour==Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet==Test2.projet:
        Label(root,text='Mauvais Match 04',column=2)

    if Test1.humour==Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet!=Test2.projet:
        Label(root,text='Mauvais Match 05',column=2)

    if Test1.humour==Test2.humour and Test1.physique==Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
        Label(root,text='Mauvais Match 06',column=2)

#Match à 25%

    if Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet==Test2.projet:
        Label(root,text='Mauvais Match 25%',text='Mauvais Match 001',column=2)

    if Test1.humour!=Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence==Test2.intelligence and Test1.projet!=Test2.projet:
        Label(root,text='Mauvais Match 002',column=2)

    if Test1.humour==Test2.humour and Test1.physique!=Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
        Label(root,text='Mauvais Match 003',column=2)

    if Test1.humour!=Test2.humour and Test1.physique==Test2.physique and Test1.intelligence!=Test2.intelligence and Test1.projet!=Test2.projet:
        Label(root,text='Mauvais Match 004',column=2)
#characteristics
hommes = {}
femmes = {}

Bryan=Candidat("homme",4,5,3,2)
Adrien=Candidat("homme",2,3)
Marin=Candidat("homme",3)
Alcaraz=Candidat("homme",1)
Allan=Candidat("homme",1)
Seby =Candidat("homme",1)
hommes['Bryan'] = Bryan
hommes['Adrien'] = Adrien
hommes['Marin'] = Marin
hommes['Alcaraz'] = Alcaraz
hommes['Allan'] = Allan
hommes['Seby'] = Seby
#--------------------------------#
Anissa=Candidat("femme",0)
Melanie=Candidat("femme",3)
Dita =Candidat("femme",2)
LeaMary=Candidat("femme",1)
Maisanne=Candidat("femme",1)
Kellyn=Candidat("femme",1)
femmes['Anissa'] = Anissa
femmes['Melanie'] = Melanie
femmes['Dita'] = Dita
femmes['LeaMary'] = LeaMary
femmes['Maisanne'] = Maisanne
femmes['Kellyn'] = Kellyn


#I don't know if these 3 lines are still useful
'''
#I don't know if these 3 lines are still useful
homme = input("Choisir le prénom d'un homme : ")#input Man
femme = input("Choisir le prénom d'une femme : ")#input Woman
compare(hommes[homme],femmes[femme])'''

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...