0
0 комментариев

Нужно обновлять надписи (labels) по нажатию кнопки, но вот функция с root.update() не работает. Что не так?

from tkinter import *
import random
import decimal
 
# random numbers
random1 = decimal.Decimal(random.randrange(-155, 548))/100
random2 = decimal.Decimal(random.randrange(-155, 548))/100
 
 
root = Tk()
root.title("Cheking numbers")
root.geometry("640x480")
root.resizable(width=False, height=False)
 
 
# creating click event function
def ResultFunction():
    if random1 - random2 > 1.30:
        ResultLabel.configure(text='Result:' + str(random1 - random2))
    elif random1 < - 0.80 and random2 > -0.80:
        ResultLabel.configure(text='Result:' + str(random1))
    elif random1 > - 0.80 and random2 < -1.30:
        ResultLabel.configure(text='Result:' + str(random2))
    elif random1 < -0.80 and random2 < -1.30 and random1 < random2:
        ResultLabel.configure(text='Result:' + str(random1))
    elif random1 < -0.80 and random2 < -1.30 and random1 < random2:
        ResultLabel.configure(text='Result:' + str(random2))
    else:
        ResultLabel.configure(text='Result: 0')
 
 
# creating function for refreshing labels
def RefreshLabels():
    root.update()
 
 
# Labels
Number1Label = Label(root, text=str(random1), font='georgia 20')
Number1Label.pack()
 
 
Number2Label = Label(root, text=str(random2), font='georgia 20')
Number2Label.pack()
 
 
ResultLabel = Label(root, text='Result:', font='georgia 20')
ResultLabel.pack()
 
 
# Buttons
ResultButton = Button(root, text='Result', width=5, height=1, bg='white', fg='green', font='georgia 20', command=ResultFunction)
ResultButton.pack()
 
 
NextButton = Button(root, text='Next', width=6, height=1, bg='white', fg='green', font='georgia 20', command=RefreshLabels)
NextButton.pack()
 
 
 
mainloop()


Добавить комментарий