vendredi 2 avril 2021

Why is this label not changing when I use the config option?

So I kind of want this tiny bot to talk and respond to you when you put stuff in this entry by using config and if statements but it doesn't really seem to work. my problem now is that the label here is changing when I make the config thing. Here's my code:

import tkinter as tk

root = tk.Tk()
root.attributes('-fullscreen', True)


exit_button = tk.Button(root, text="Exit", command = root.destroy)
exit_button.place(x=1506, y=0)


def answer():
    global main_entry, answer_label
    if main_entry == "Hey":
        answer_label.config(Text = "Hi")

frame = tk.Frame(root)
main_entry = tk.Entry(frame, width=100)
main_entry.grid(row=0, column=0)
go_button = tk.Button(frame, text='Go!', width=85, command = answer)
go_button.grid(row=1, column=0)
answer_label = tk.Label(text = "Hello!").pack()
frame.place(relx=.5, rely=.5, anchor='center')

root.mainloop()

The problem is the if statement isn't working and it isn't changing the ext but I'm also not getting any error messages so I'm a bit confused.

Aucun commentaire:

Enregistrer un commentaire