Zone d'entrée Python
Fatima
-
Fatima -
Fatima -
Bonjour, j'aimerais savoir comment faire afficher un texte dans une zone d'entrée Tkinter après l'appui d'un bouton spécifique. Mon programme est une magic8ball muni d'une interface graphique. J'écris la question dans une zone d'entrée 'Question', je clique sur le bouton 'Répondre' mais rien ne s'affiche dans la zone d'entrée 'Réponse'. Voici le programme :
import sys
import random
from tkinter import *
from tkinter import ttk
root = Tk()
root.title('Fatima Magic8Ball')
root.resizable(0,0)
ttk.Label(text='Magic8Ball',style='Header.TLabel').grid(row=0,columnspan=4)
ttk.Label(text='Question',style='Header.TLabel').grid(row=3,column=0)
ttk.Label(text='Réponse',style='Header.TLabel').grid(row=4,column=0)
Question_entry = ttk.Entry(width=50)
Question_entry.grid(row=3,column=1)
Réponse_entry = ttk.Entry(width=50)
Réponse_entry.grid(row=4,column=1)
def Répondre():
answers = random.randint(1,8)
if answers == 1:
("It is certain")
elif answers == 2:
("Outlook good")
elif answers == 3:
("You may rely on it")
elif answers == 4:
("Ask again later")
elif answers == 5:
("Concentrate and ask again")
elif answers == 6:
("Reply hazy, try again")
elif answers == 7:
("My reply is no")
elif answers == 8:
("My sources say no")
Répondre_button = ttk.Button(text='Répondre',command = lambda: Répondre()).grid(row=5,column=0)
root.mainloop()
Merci de m'aider.
import sys
import random
from tkinter import *
from tkinter import ttk
root = Tk()
root.title('Fatima Magic8Ball')
root.resizable(0,0)
ttk.Label(text='Magic8Ball',style='Header.TLabel').grid(row=0,columnspan=4)
ttk.Label(text='Question',style='Header.TLabel').grid(row=3,column=0)
ttk.Label(text='Réponse',style='Header.TLabel').grid(row=4,column=0)
Question_entry = ttk.Entry(width=50)
Question_entry.grid(row=3,column=1)
Réponse_entry = ttk.Entry(width=50)
Réponse_entry.grid(row=4,column=1)
def Répondre():
answers = random.randint(1,8)
if answers == 1:
("It is certain")
elif answers == 2:
("Outlook good")
elif answers == 3:
("You may rely on it")
elif answers == 4:
("Ask again later")
elif answers == 5:
("Concentrate and ask again")
elif answers == 6:
("Reply hazy, try again")
elif answers == 7:
("My reply is no")
elif answers == 8:
("My sources say no")
Répondre_button = ttk.Button(text='Répondre',command = lambda: Répondre()).grid(row=5,column=0)
root.mainloop()
Merci de m'aider.
A voir également:
- App.citizencode.net
- Alternative zone telechargement - Accueil - Outils
- Citizen code python avis - Accueil - Outils
- Zone alarm - Télécharger - Pare-feu
- Python est introuvable. exúcutez sans argument pour procúder ó l - Forum Python
- Zone annuaire guru - Accueil - Services en ligne
1 réponse
yg_be
Messages postés
23541
Date d'inscription
Statut
Contributeur
Dernière intervention
Ambassadeur
1 584
bonjour,
où essaies-tu d'afficher quelque chose dans la zone 'Réponse'?
peux-tu utiliser les balises de code, comme expliqué ici: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
où essaies-tu d'afficher quelque chose dans la zone 'Réponse'?
peux-tu utiliser les balises de code, comme expliqué ici: https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Question_entry = ttk.Entry(width=50) après avoir appuyé sur le bouton Répondre_button.
Désolée si je n'ai pas bien expliqué mon problème, je suis débutante, je viens de commencer Python.