Hallo zusammen! Ich habe gerade mit Python ein Programm geschrieben, dass Morgens "Guten Morgen", Mittags "Guten Mittag" usw. anzeigen soll. Ich habe schon mehrere Ideen von mir ausprobiert, weiß aber nicht, was ich falsch gemacht habe.
Das ist mein Programm:
import tkinter as tk
from tkinter import ttk
from datetime import datetime as dt
Stunde = dt.hour()
def Say_hello():
if Stunde <= 11 and Stunde >=4:
Label2 = ttk.Label(root, text="Guten Morgen!")
Label2.pack()
elif Stunde >= 12 and Stunde <= 14:
Label3 = ttk.Label(root, text="Guten Mittag!")
Label3.pack()
elif Stunde >= 15 and Stunde <= 17:
Label4 = ttk.Label(root, text="Guten Nachmittag!")
Label4.pack()
elif Stunde >= 18 and Stunde <= 23:
Label5 = ttk.Label(root, text="Guten Abend!")
Label5.pack()
elif Stunde > 23 and Stunde < 4:
Label6 = ttk.Label(root, text="Gute Nacht!")
Label6.pack()
root = tk.Tk()
root.title("Say hello!")
root.geometry("800x400")
Button1 = ttk.Button(root, text="Einloggen", command=Say_hello)
Button1.pack(side="bottom", fill="x")
root.mainloop()
Ich würde mich sehr über eine Antwort freuen.
LG LukaRahn