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.
1 réponse
-
yg_be Messages postés 23437 Date d'inscription Statut Contributeur Dernière intervention Ambassadeur 1 588
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-
-
Bonjour, merci d'avoir essayé de répondre à ma question. J'essaie d'afficher l'une des réponses suivantes aléatoirement : "It is certain", "Outlook good", "You may rely on it", "Ask again later", "Concentrate and ask again", "Reply hazy, try again", "My reply is no", "My sources say no", à l'aide de "random.randint" dans la zone d'entrée Réponse que j'ai crée dans la ligne suivante :
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.
-