Probleme pour inserer des donnée dans un formulaire
vlatipa -
Bonjour, je voudrais récupérer des données de 2 programmes python afin de remplir les champs "ENTRY" .Je voudrais egalement inserer des nombres decimaux dans le premier champ en utilisant le programme ci_dessous . La fonction "Nums" génere des nombres aléatoires, c'est cette fonction que je voudrais inserer dans mon formulaire Voici mes programmes :
class Max: def __init__(self, bps, bgs, bops, bogs, gops, gogs, to1, to2): self.bps = bps self.bgs = bgs self.bops = bops self.bogs = bogs self.gops = gops self.gogs = gogs self.to1 = to1 self.to2 = to2 def Affiche_seq(self): print(f"Base: {self.bps, self.bgs}") print(f"Bo: {self.bops, self.bogs}") print(f"Go: {self.gops, self.gogs}") print(f"Tocard: {self.to1, self.to2}") def _bps(self): return sorted(self.bps) def _bgs(self): return sorted(self.bgs) def _bops(self): return sorted(self.bops) def _bogs(self): return sorted(self.bogs) def _gops(self): return sorted(self.gops) def _gogs(self): return sorted(self.gogs) def _to1(self): return sorted(self.to1) def _to2(self): return sorted(self.to2) def Nums(): num =[float(x) for x in input('cote : ').split()] return num num=Nums() bps = [] bgs = [] for nombre in num: if 0 < nombre <8.5: bps.append(nombre) if 8.5 < nombre < 10.8: bgs.append(nombre) bops = [] bogs = [] for nombre in num: if 10.9 < nombre < 14.8: bops.append(nombre) if 14.9 < nombre < 20.5: bogs.append(nombre) gops = [] gogs = [] for nombre in num: if 20.6 < nombre < 24.8: gops.append(nombre) if 24.9 < nombre < 34.8: gogs.append(nombre) to1 = [] to2 = [] for nombre in num: if 34.9 < nombre < 44.5: to1.append(nombre) elif 44.6 < nombre < 315.5: to2.append(nombre) r = Max(bps, bgs, bops, bogs, gops, gogs, to1, to2) print(r.Affiche_seq())
Voici mon programme intitulé "BO", je voudrais inserer ses données de ce programme dans le 3éme champs "Entry de mon programme "formulaire"
from partants import * class B: def __init__(self, s, p): self.bops = s self.bogs = p def range_bo(self): self.bo = self.bops + self.bogs r = len(self.bo) a = len(self.bops) b = len(self.bogs) if r == 9: if a == 4 and b == 5: print(self.bo[4], self.bo[7], self.bo[8]) print(self.bo[0], self.bo[2], self.bo[3]) elif a == 5 and b == 4: print(self.bo[1], self.bo[2]) print(self.bo[1], self.bo[4]) elif a == 2 and b == 7: print("") elif a == 7 and b == 2: print("") elif a == 6 and b == 3: print(self.bo[3], self.bo[6], self.bo[7], self.bo[5]) elif a == 3 and b == 6: print(self.bo[1], self.bo[3], self.bo[5], self.bo[6]) print(self.bo[2], self.bo[3], self.bo[4]) elif a == 7 and b == 2: print("") elif a == 2 and b == 7: print("") elif a == 1 and b == 8: print("") elif a == 8 and b == 1: print("") if r == 8: if a == 3 and b == 5: print(self.bo[2], self.bo[3]) elif a == 6 and b == 2: print("") elif a == 4 and b == 4: print(self.bo[1], self.bo[2], self.bo[3], self.bo[6]) elif a == 2 and b == 6: print(self.bo[4], self.bo[5], self.bo[7]) elif a == 1 and b == 8: print("") elif a == 8 and b == 1: print("") if r == 7: if a == 4 and b == 3: print(self.bo[0], self.bo[1], self.bo[2], self.bo[3]) print(self.bo[2], self.bo[3], self.bo[5], self.bo[6]) print(self.bo[0], self.bo[3], self.bo[6]) print(self.bo[2], self.bo[3], self.bo[4]) print(self.bo[1], self.bo[2], self.bo[3]) print(self.bo[2], self.bo[6]) print(self.bo[2], self.bo[4]) print(self.bo[1]) elif a == 3 and b == 4: print(self.bo[0], self.bo[2], self.bo[5]) print(self.bo[0], self.bo[2]) print(self.bo[3], self.bo[5]) print(self.bo[1], self.bo[4]) print(self.bo[0]) elif a == 5 and b == 2: print("", self.bo[3], self.bo[4]) print(self.bo[0], self.bo[2], self.bo[3], self.bo[4]) elif a == 2 and b == 5: print(self.bo[1], self.bo[3], self.bo[4]) print(self.bo[0], self.bo[3], self.bo[4]) print(self.bo[0]) elif a == 1 and b == 6: print(self.bo[1], self.bo[2]) print(self.bo[0], self.bo[4]) print(self.bo[-2]) elif a == 6 and b == 1: print("") elif a == 7 and b == 0: print("") elif a == 0 and b == 7: print("") if r == 6: if a == 3 and b == 3: print(self.bo[1], self.bo[2], self.bo[3], self.bo[4]) print(self.bo[1], self.bo[2], self.bo[4], self.bo[5]) print(self.bo[0], self.bo[3], self.bo[4]) print(self.bo[1], self.bo[3], self.bo[4]) print(self.bo[1], self.bo[4], self.bo[5]) print(self.bo[1], self.bo[2], self.bo[5]) print(self.bo[0], self.bo[4]) print(self.bo[1], self.bo[3]) print(self.bo[1], self.bo[4]) print(self.bo[4]) elif a == 2 and b == 4: print(self.bo[0], self.bo[1], self.bo[-1]) print(self.bo[-2]) print(self.bo[3], self.bo[5]) print("") print(self.bo[1]) elif a == 4 and b == 2: print(self.bo[2], self.bo[4]) print(self.bo[4]) print(self.bo[2]) elif a == 1 and b == 5: print(self.bo[3]) print(self.bo[0], self.bo[2]) elif a == 5 and b == 1: print(self.bo[0], self.bo[2], self.bo[3], self.bo[5]) print(self.bo[1], self.bo[2], self.bo[4]) print(self.bo[2]) print(self.bo[3], self.bo[4]) elif a == 6 and b == 0: print(self.bo[0], self.bo[2]) elif a == 0 and b == 6: print("") if r == 5: if a == 2 and b == 3: print(self.bo[0], self.bo[2], self.bo[4]) print(self.bo[1], self.bo[3], self.bo[4]) print(self.bo[0], self.bo[3], self.bo[4]) print(self.bo[1], self.bo[3]) print(self.bo[0], self.bo[2]) print(self.bo[1], self.bo[2]) print(self.bo[1], self.bo[4]) print(self.bo[2]) print(self.bo[0]) elif a == 3 and b == 2: print(self.bo[0], self.bo[1], self.bo[2], self.bo[4]) print(self.bo[0], self.bo[3]) print(self.bo[2], self.bo[3]) print(self.bo[0], self.bo[2]) print(self.bo[1]) print(self.bo[2]) elif a == 1 and b == 4: print(self.bo[1], self.bo[4]) print(self.bo[3], self.bo[4]) print(self.bo[2], self.bo[4]) print(self.bo[0], self.bo[-1]) print(self.bo[4]) elif a == 4 and b == 1: print(self.bo[0], self.bo[3], self.bo[4]) print(self.bo[2], self.bo[3], self.bo[4]) print(self.bo[0]) print(self.bo[3]) elif a == 5 and b == 0: print(self.bo[2], self.bo[4]) elif a == 0 and b == 5: print("") if r == 4: if a == 2 and b == 2: print(self.bo[1], self.bo[2], self.bo[3]) print(self.bo[0], self.bo[2], self.bo[3]) print(self.bo[0], self.bo[2]) print(self.bo[1], self.bo[2]) print(self.bo[0], self.bo[-1]) print(self.bo[2], self.bo[3]) print(self.bo[0]) print(self.bo[1]) print(self.bo[3]) elif a == 3 and b == 1: print(self.bo[1], self.bo[2]) print(self.bo[1], self.bo[3]) print(self.bo[3]) elif a == 1 and b == 3: print(self.bo[0], self.bo[2], self.bo[3]) print(self.bo[1], self.bo[3]) print(self.bo[1], self.bo[2]) print(self.bo[0], self.bo[2]) print(self.bo[3]) print(self.bo[1]) elif a == 4 and b == 0: print(self.bo[1], self.bo[3]) elif a == 0 and b == 4: print(self.bo[0], self.bo[2], self.bo[3]) print(self.bo[1], self.bo[3]) print(self.bo[1], self.bo[2]) if r == 3: if a == 1 and b == 2: print(self.bo[0], self.bo[2]) print(self.bo[1], self.bo[2]) print(self.bo[0]) print(self.bo[1]) print(self.bo[2]) elif a == 2 and b == 1: print(self.bo[2]) elif a == 0 and b == 3: print(self.bo[1]) print(self.bo[2]) elif a == 3 and b == 0: print(self.bo[1]) print(self.bo[2]) if r == 2: if a == 0 and b == 2: print(self.bo[0]) elif a == 2 and b == 0: print(self.bo[2]) elif a == 1 and b == 1: print(self.bo[0]) print(self.bo[1]) if r == 1: if a == 0 and b == 1: print(self.bo[0]) elif a == 1 and b == 0: print(self.bo[0]) a = Max(bps, bgs, bops, bogs, gops, gogs, to1, to2) s = a._bops() p = a._bogs() e = B(s, p) print(e.range_bo())
Voici mon programme "Formulaire" ,Quelqu'un pourrait m'aider à remplir les champs entry svp
from functools import partial from tkinter import * from tkinter import ttk, messagebox from partants import Max, Nums from BO import B class Login: def __init__(self,root): self.root =root self.root.title("Samaritain") self.root.resizable(False,False) self.root.geometry("1550x780+500+500") self.root.configure(bg="#164159") #Ajouter un titre lblTitre = Label(root,text="Enregistrement des partants",font=('sans serif',20),bg="#164159",fg="white").place(x=10,y=20, width=600) lblTitre1 = Label(root, text="Repartition des cotes", font=('sans serif', 20), bg="#164159",fg="white").place(x=10, y=170, width=600) lblTitre2 = Label(root, text="Resultat", font=('sans serif', 20), bg="#164159", fg="white").place(x=10, y=630, width=600) lblbase = Label(root,text="Base:",font=('sans serif',16),bg="#164159",fg="white").place(x=5,y=270, width=200) lblbo = Label(root, text="BO:", font=('sans serif', 16), bg="#164159", fg="white").place(x=5, y=380,width=200) lblgo = Label(root, text="GO:", font=('sans serif', 16), bg="#164159", fg="white").place(x=5, y=470,width=200) lbltocard = Label(root, text="Tocard:", font=('sans serif', 16), bg="#164159", fg="white").place(x=5, y=560, width=200) #Variables value=DoubleVar(root) value1= DoubleVar(root) value2= DoubleVar(root) value3= DoubleVar(root) value4 = DoubleVar(root) #les champs self.entryTitre = Entry(root, bd=4,textvariable=value, font=("arial", 15)).place(x=170, y=100, width=450) self.entrybase = Entry(root,bd=4,textvariable=value1,font=("arial",15)).place(x=170,y=270,width=450) self.entrybo = Entry(root, bd=4,textvariable=value2, font=("arial", 15)).place(x=170, y=380, width=450) self.entrygo = Entry(root, bd=4,textvariable=value3, font=("arial", 15)).place(x=170, y=470, width=450) self.entrytocard = Entry(root,textvariable=value4, bd=4, font=("arial", 15)).place(x=170, y=560, width=450) self.entryresultat = Entry(root, bd=4, font=("arial", 15)).place(x=170, y=710, width=450) #Ajouter boutons btnenregistrer = Button(root, text="ENREGISTRER", bd= 2, command=partial(self.update_entry(value,value2,value3,value4)),font=("arial", 15), bg="#3AD50C").place(x=670,y=310,width=50) btnsupprimer = Button(root, text="SUPPRIMER", bd=2,font=("arial",15),bg="#D50C22") #Ajouter table table = ttk.Treeview(root, columns=(1, 2, 3), height=10, show="headings") table.place(x=730, y=10, width=700, height=250) table.heading('1', text="Date") table.heading('2', text="Pronostiques") table.heading('3', text="Resultat") table.column(1, width=100) table.column(2, width=100) table.column(3, width=100) def update_entry(self,var1,var2,var3,var4): value= var1.get() value2=var2.get() value3=var3.get() value4 = var4.get() var1.set() var2.set() print(value) root= Tk() obj = Login(root) root.mainloop()
Windows / Chrome 107.0.0.0
- Probleme pour inserer des donnée dans un formulaire
- Whatsapp formulaire opposition - Guide
- Insérer une vidéo dans powerpoint - Guide
- Insérer signature word - Guide
- Formulaire de réclamation facebook - Guide
- Insérer un espace insécable dans word - Guide
3 réponses
bonjour,
peux-tu donner un exemple de ce que tu veux réaliser?
Bonjour,
Le deux premiers programmes sont des pronostiques de courses hippiques et le 3éme programme est un interface graphique en guise de formulaire.
Je cherche que l'utilisateur saisissent les cotes des chevaux ,avec la fonction Nums() situé dans le premier programme. Par la suite ses numeros se repartissent selon la valeur de leur cotes en quatre categorie:
-Base, (0 a 10)
-BO(bon outsiders), (10.5 a 20)
-GO(Gros outsiders) (20,5 à 30)
-tocards (30,5 à 200)
Sur le message precedent, j'ai programmé les pronostiques que pour la catégorie BO. Un exemple afin qu'on puisse me montrer comment afficher ce programme sur un tableau Treeview ou sur un champ Entry() dans mon interface graphique
J'aimerais afficher les données de mon programme BO sur un champs "Entry()" de mon formulaire tkintermais le probléme est que je n'arrive pas à importer le fichier de mon programme BO et je connais pas manipuler les variable get() et set(), de plusj'aimerais saisir, enregistrer et supprimer les numeros uniquement sur l'interface graphique et non sur le powershell.
Tu n'as pas donné d'exemple de ce que tu voulais visualiser.
Si tu adaptes le code de "Formulaires", en remplaçant la ligne 4 par "import partants" et en ajoutant, après la ligne 33:
value2.set(partants.r._bogs())
Alors tu auras, si tu rentres "10 20 30" comme cotes, "20" affiché comme "BO" dans ton formulaire.
Bonsoir, qu'est supposé faire ton programme ?
Faire des combinaisons de favoris et outsiders d'un tiercé, quinté ? Je ne comprends pas les critères d'affichage dans ta méthode range_bo de ta class B, il faudrait quand même nommer tout cela correctement.
Utilise aussi des structures de données adaptées, dans ta classe Max (pourquoi ce nom ?) un dictionnaire serait plus judicieux comme choix de structure plutôt que moult attributs, ainsi plus besoin de getter pour chaque attributs.
On pourrait de ce fait arriver à une base comme.
class Max: def __init__(self, nums): self.data_build(nums) def data_build(self, numbers): params = ( (8.5, "bps"), (10.8, "bgs"), (14.8, "bops"), (20.5, "bogs"), (24.8, "gops"), (34.8, "gogs"), (44.5, "to1"), (315.5, "to2"), # pourquoi 315.5 ? ) self.data = {v[1]: [] for v in params} for n in numbers: for max_, key in params: if n < max_: self.data[key].append(n) break else: raise ValueError(f"n >= {params[-1][0]}") def __repr__(self): return ( f"Base: {self.data['bps']}, {self.data['bgs']}\n" f"Bo: {self.data['bops']}, {self.data['bogs']}\n" f"Go: {self.data['gops']}, {self.data['gogs']}\n" f"Tocard: {self.data['to1']}, {self.data['to2']}\n" ) def __getattr__(self, key): try: return sorted(self.data[key].copy()) except KeyError: raise KeyError(f"key {key} not in data") def get_numbers(): # Vérifier les cotes saisies ! return (float(x) for x in input("cote : ").split() if 0 < float(x) < 315.5) numbers = get_numbers() maxs = Max(numbers) print(maxs) print(maxs.bogs)
Mais ne sachant la finalité du programme, sans doute que tout est à revoir.
Bonne continuation.