Created
September 19, 2019 17:07
-
-
Save GravenilvecTV/ea67f51a84deacb456cf9bc4a0fffff9 to your computer and use it in GitHub Desktop.
CORRIGE TP 2 : GENERATEUR DE CHOIX DE REPAS (UI)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
from tkinter import * | |
def generate_random_meal_suggestion(): | |
if os.path.exists("meals.txt"): | |
with open("meals.txt", "r") as file: | |
meal_random_choice = random.choice(file.readlines()) | |
random_meal_title.config(text=meal_random_choice, font=("Helvetica", 20), bg="#E9EA81", fg="#223E44") | |
else: | |
print("La ressource meals.txt n'existe pas") | |
# creer la fenetre | |
window = Tk() | |
window.title("Qu'allons nous manger ?") | |
window.geometry("720x480") | |
window.config(background='#E9EA81') | |
# creer la frame principale | |
frame = Frame(window, bg="#E9EA81") | |
# creer un titre | |
label_title = Label(frame, text="Qu'allons nous manger ?", font=("Helvetica", 20), bg="#E9EA81", fg="#223E44") | |
label_title.pack() | |
# choix au hasard | |
random_meal_title = Label(frame, text="Soupe", font=("Helvetica", 20), bg="#E9EA81", fg="#223E44") | |
random_meal_title.pack() | |
# creer un bouton | |
generate_password_button = Button(frame, text="Je sais pas", font=("Helvetica", 20), bg="#E9EA81", fg="#223E44", command=generate_random_meal_suggestion) | |
generate_password_button.pack(fill=X) | |
# afficher la frame | |
frame.pack(expand=YES) | |
# afficher la fenetre | |
window.mainloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kebab | |
kfc | |
tacos | |
poulet frites | |
salade | |
soupe | |
omelette |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bonjour à tous, voici ma version je vous l'accorde elle est uniquement fonctionnelle haha