Как сделать так что-бы тест на Label изменялся?

У меня проблема в том, что при нажатие кнопки Label не изменяется, пробовал с помощью лямбды, функции, IntVar. Ничего не помогает

from tkinter import *
from PIL import Image, ImageTk

# ==================== FUNCTIONS ====================


# ==================== MAIN ====================

root = Tk()
root.geometry("310x430")
root.title("Enigma")
root['bg'] = '#FF8F29'






#startentry
startentry = Entry(root, bg='#F7B237', justify=CENTER)
startentry.place(x = 10,y = 10, width=285, height=115)

#company logo
clogo = ImageTk.PhotoImage(Image.open("companylogo.jpg").resize((120, 120)))
logo = Label(root, image = clogo)
logo.place(x=10, y = 150)


#rotters
rotter1btn1 = Button(root, text='<', command = lambda: rotter1['text'] + 1)
rotter1btn2 = Button(root, text='>', command = lambda: rotter1['text'] - 1)

rotter2btn1 = Button(root, text='<', command = lambda: rotter2['text'] + 1)
rotter2btn2 = Button(root, text='>', command = lambda: rotter2['text'] - 1)

rotter3btn1 = Button(root, text='<', command = lambda: rotter2['text'] + 1)
rotter3btn2 = Button(root, text='>', command = lambda: rotter2['text'] - 1)

rotter1btn1.place(x=185, y=260)
rotter1btn2.place(x=250, y=260)
rotter2btn1.place(x=185, y=220)
rotter2btn2.place(x=250, y=220)
rotter3btn1.place(x=185, y=180)
rotter3btn2.place(x=250, y=180)

#rotters values
value1 = 0
value2 = 0
value3 = 0

rotter1 = Label(root,fg = 'black', bg = '#FF8F29', text = 0).place(x = 220, y = 260)
rotter2 = Label(root,fg = 'black', bg = '#FF8F29', text = 0).place(x = 220, y = 220)
rotter3 = Label(root,fg = 'black', bg = '#FF8F29', text = 0).place(x = 220, y = 180)

#endentry

startentry = Entry(root, bg='#F7B237', justify=CENTER)
startentry.place(x = 10,y = 305, width=285, height=115)





root.mainloop()


Ответы (1 шт):

Автор решения: retmas

Для начала смотрим на создание меток:

rotter1 = Label(root,fg = 'black', bg = '#FF8F29', text = 0).place(x = 220, y = 260)
rotter2 = Label(root,fg = 'black', bg = '#FF8F29', text = 0).place(x = 220, y = 220)
rotter3 = Label(root,fg = 'black', bg = '#FF8F29', text = 0).place(x = 220, y = 180)

Переменные rotterX у вас ничего не хранят, так как place возвращает None. Переписываем:

rotter1 = Label(root, fg='black', bg='#FF8F29', text=0)
rotter1.place(x=220, y=260)
rotter2 = Label(root, fg='black', bg='#FF8F29', text=0)
rotter2.place(x=220, y=220)
rotter3 = Label(root, fg='black', bg='#FF8F29', text=0)
rotter3.place(x=220, y=180)

Теперь смотрим на создание кнопок, в частности, command:

rotter1btn1 = Button(root, text='<', command = lambda: rotter1['text'] + 1)
rotter1btn2 = Button(root, text='>', command = lambda: rotter1['text'] - 1)
...

В лямбде к тексту метки прибавляется число и, затем, результат... куда, зачем, что с ним?
Можно сделать, например, так:

def rotter_add(rotter: Label, count: int = 1):
    rotter.configure(text=rotter["text"] + count)

rotter1btn1 = Button(root, text='<', command=lambda: rotter_add(rotter1, -1))
rotter1btn2 = Button(root, text='>', command=lambda: rotter_add(rotter1))
...
→ Ссылка