Я уверен, что это очень простая проблема для вас, но огромная для меня.
Я не знаю, как создать команду для моей кнопки tkinter с помощью if и else.
На самом деле, идея заключается в том, что, когда я вводю в элементе слово «белый» после нажатия кнопки, на нем должна отображаться метка «ВПРАВО», но с этим кодом кнопка всегда показывает НЕПРАВИЛЬНО ... почему?
Это код:
# coding=utf-8
from tkinter import *
from tkinter import font
from PIL import ImageTk,Image
import time
from PIL import ImageTk,Image
schermata = Tk()
ment = StringVar()
schermata.geometry('750x500')
schermata.title('DANTE')
def comando():
global input
if ment=='white':
time.sleep(1)
risposta_giusta.pack()
risposta_giusta.place(x=20, y=290)
else:
time.sleep(1)
risposta_sbagliata.pack()
risposta_sbagliata.place(x=20,y=290)
def resize_image(event):
new_width = event.width
new_height = event.height
image = copy_of_image.resize((new_width, new_height))
photo = ImageTk.PhotoImage(image)
label.config(image = photo)
label.image = photo #avoid garbage collection
image = Image.open('dante.gif')
copy_of_image = image.copy()
photo = ImageTk.PhotoImage(image)
label = Label(schermata, image = photo)
label.bind('<Configure>', resize_image)
label.pack(fill=BOTH, expand = YES)
font = ('Ubuntu',22)
font_2 = ('Ubuntu',12)
labelfont = ('Noto Serif CJK SC', 35, 'bold')
titolo = Label(schermata,text='DANTE',bg='#E5E3C6',fg='#BF000D')
titolo.config(font=labelfont)
titolo.pack(fill=BOTH, expand = YES)
titolo.place(x=20, y=20)
risposta_giusta = Label(schermata, text='RIGHT!!', font=font, bg='#E5E3C6',fg='#0F0000')
risposta_sbagliata = Label(schermata, text='WRONG', font=font, bg='#E5E3C6',fg='#0F0000')
domanda = Label(schermata, text="what is the color of Napoleone's horse?", font=font_2, bg='#E5E3C6',fg='red')
domanda.pack()
domanda.place(x=20, y=120)
input = Entry(schermata,textvariable=ment,bg='white',width=23,disabledbackground='black')
input.pack(ipady=3)
input.place(x=20, y=190)
bottone = Button(schermata,text='PARLA CON DANTE',command=comando,bg='#BF000D',fg='white')
bottone.pack()
bottone.place(x=20, y=245)
schermata.mainloop()