python - 用另一个函数替换一个函数
问题描述
我正在尝试用下面的 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',bg="pink",fg="black").grid(row=0,column=3)
Male = Entry(root)
Male.grid(row=1,column=1)
Label(root,text='&',bg="pink",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",fg="white").grid(row=3,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%',bg="green",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%',bg="red",fg="white").grid(row=4,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%',bg="red",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 1',bg="red",fg="white").grid(row=4,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 75%',bg="red",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 2',bg="red",fg="white").grid(row=4,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 75%',bg="red",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 3',bg="red",fg="white").grid(row=4,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 75%',bg="red",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 4',bg="red",fg="white").grid(row=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%',bg="red",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 01',bg="red",fg="white").grid(row=4,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 50%',bg="red",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 02',bg="red",fg="white").grid(row=4,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 50%',bg="red",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 03',bg="red",fg="white").grid(row=4,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 50%',bg="red",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 04',bg="red",fg="white").grid(row=4,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 50%',bg="red",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 05',bg="red",fg="white").grid(row=4,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 50%',bg="red",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 06',bg="red",fg="white").grid(row=4,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%',bg="red",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 001',bg="red",fg="white").grid(row=4,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 25%',bg="red",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 002',bg="red",fg="white").grid(row=4,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 25%',bg="red",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 003',bg="red",fg="white").grid(row=4,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 25%',bg="red",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 004',bg="red",fg="white").grid(row=4,column=2)
#characteristics
hommes = {}
femmes = {}
Bryan=Candidat("homme",4,5,3,2)
Adrien=Candidat("homme",4,3,2,3)
Marin=Candidat("homme",5,2,4,3)
Alcaraz=Candidat("homme",4,3,2,1)
Allan=Candidat("homme",4,3,2,1)
Seby =Candidat("homme",4,3,2,1)
hommes['Bryan'] = Bryan
hommes['Adrien'] = Adrien
hommes['Marin'] = Marin
hommes['Alcaraz'] = Alcaraz
hommes['Allan'] = Allan
hommes['Seby'] = Seby
#--------------------------------#
Anissa=Candidat("femme",0,5,2,0)
Melanie=Candidat("femme",5,3,4,3)
Dita =Candidat("femme",4,4,3,2)
LeaMary=Candidat("femme",4,3,2,1)
Maisanne=Candidat("femme",4,3,2,1)
Kellyn=Candidat("femme",4,3,2,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])'''
解决方案
推荐阅读
- html - CSS 或 HTML:将两个圆形 div 放在另一个 div 旁边
- html - 使用 CSS 为小屏幕保持图像的纵横比
- ios - SwiftUI - iOS 14.5 更新导航栏问题
- android - 如何在播放时识别音频文件的内容/在播放时更改音高值?
- spring-boot - Open Api 3 生成器不会为 $ref 引用的路径生成类
- migration - Salesforce 连接器和批处理作业如何使它们以分页方式工作,最好的方式是什么?
- spring-boot - 在 Spring Boot Camel 应用程序公开的 Micrometer / Prometheus 信息中包含其他 JMX 指标
- sql - 正确的集合操作是在一组集合中找到匹配的集合,还是完全连接?
- javascript - 我该如何解决这个 JavaScript 挑战?
- kubernetes - 确保将正确版本的代码部署到 Kubernetes 的最佳方法是什么?