Проблемы с выводом информации в Entry

Рейтинг: 0Ответов: 1Опубликовано: 19.06.2023

Делаю простой калькулятор, почему-то функции выполняются сразу, а при нажатии кнопок не работают, помогите, пожалуйста

import tkinter as t


root = t.Tk()
root.geometry('512x410')

pole = t.Entry(width=19, font='Arial, 35', justify='right')
pole.grid(row=0, column=0, columnspan=4)

def but7():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '7')
def but8():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '8')
def but9():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '9')
def but_del():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '/')
def but4():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '4')
def but5():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '5')
def but6():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '6')
def but_umn():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '*')
def but1():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '1')
def but2():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '2')
def but3():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '3')
def but_min():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '-')
def but_zap():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '.')
def but0():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '0')
def but_ravn():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '=')
def but_plus():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '+')

b7 = t.Button(text='7', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but7())
b7.grid(row=1, column=0) # 7
b8 = t.Button(text='8', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but8())
b8.grid(row=1, column=1) # 8
b9 = t.Button(text='9', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but9())
b9.grid(row=1, column=2) # 9
b_del = t.Button(text='/', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_del())
b_del.grid(row=1, column=3) # /
b4 = t.Button(text='4', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but4())
b4.grid(row=2, column=0) # 4
b5 = t.Button(text='5', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but5())
b5.grid(row=2, column=1) # 5
b6 = t.Button(text='6', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but6())
b6.grid(row=2, column=2) # 6
b_umn = t.Button(text='*', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_umn())
b_umn.grid(row=2, column=3) # x
b1 = t.Button(text='1', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but1())
b1.grid(row=3, column=0) # 1
b2 = t.Button(text='2', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but2())
b2.grid(row=3, column=1) # 2
b3 = t.Button(text='3', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but3())
b3.grid(row=3, column=2) # 3
b_min = t.Button(text='-', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_min())
b_min.grid(row=3, column=3) # -
b_zap = t.Button(text=',', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_zap())
b_zap.grid(row=4, column=0) # ,
b0 = t.Button(text='0', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but0())
b0.grid(row=4, column=1) # 0
b_ravn = t.Button(text='=', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_ravn())
b_ravn.grid(row=4, column=2) # =
b_plus = t.Button(text='+', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_plus())
b_plus.grid(row=4, column=3) # +



root.mainloop()

Ответы

▲ 0

Потому что вы их вызываете а не передаете.

import tkinter as t


root = t.Tk()
root.geometry('512x410')

pole = t.Entry(width=19, font='Arial, 35', justify='right')
pole.grid(row=0, column=0, columnspan=4)

def but7():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '7')
def but8():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '8')
def but9():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '9')
def but_del():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '/')
def but4():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '4')
def but5():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '5')
def but6():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '6')
def but_umn():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '*')
def but1():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '1')
def but2():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '2')
def but3():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '3')
def but_min():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '-')
def but_zap():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '.')
def but0():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '0')
def but_ravn():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '=')
def but_plus():
    p_text = pole.get()
    p_len = len(p_text)
    pole.insert(p_len, '+')

b7 = t.Button(text='7', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but7)
b7.grid(row=1, column=0) # 7
b8 = t.Button(text='8', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but8)
b8.grid(row=1, column=1) # 8
b9 = t.Button(text='9', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but9)
b9.grid(row=1, column=2) # 9
b_del = t.Button(text='/', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_del)
b_del.grid(row=1, column=3) # /
b4 = t.Button(text='4', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but4)
b4.grid(row=2, column=0) # 4
b5 = t.Button(text='5', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but5)
b5.grid(row=2, column=1) # 5
b6 = t.Button(text='6', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but6)
b6.grid(row=2, column=2) # 6
b_umn = t.Button(text='*', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_umn)
b_umn.grid(row=2, column=3) # x
b1 = t.Button(text='1', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but1)
b1.grid(row=3, column=0) # 1
b2 = t.Button(text='2', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but2)
b2.grid(row=3, column=1) # 2
b3 = t.Button(text='3', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but3)
b3.grid(row=3, column=2) # 3
b_min = t.Button(text='-', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_min)
b_min.grid(row=3, column=3) # -
b_zap = t.Button(text=',', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_zap)
b_zap.grid(row=4, column=0) # ,
b0 = t.Button(text='0', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but0)
b0.grid(row=4, column=1) # 0
b_ravn = t.Button(text='=', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_ravn)
b_ravn.grid(row=4, column=2) # =
b_plus = t.Button(text='+', font=('Arial', 15, 'bold'), bd=1, width=10, height=3, command=but_plus)
b_plus.grid(row=4, column=3) # +



root.mainloop()