例如,当我按下“100”时,在文本框中输出“001”。我尝试在索引中使用 -1 但同样的事情仍然发生,我也尝试执行 .insert(0.end, num) 但它会引发错误。我怎样才能让数字总是在输出的末尾输入。此外,这是使用 tkinter 输出数字的最佳方式还是有其他方式?
from tkinter import *
import operator
window = Tk()
window.title('Calculator')
def click(num):
output.insert(0.0, num) #numbers not properly inputted (bug)
#output for calculator
output = Text(window, font = 'none 12 bold', height = 4, width = 25, wrap = 'word')
output.grid(row = 0, column = 0, columnspan = 4, pady = 10)
###buttons
#clear and operators
b_clear = Button(window, text = 'C', width = 7, height = 3)
b_clear.grid(row = 1, column = 2, padx = (10, 0))
b_div = Button(window, text = '/', width = 7, height = 3)
b_div.grid(row = 1, column = 3, padx = 10)
b_mult = Button(window, text = '*', width = 7, height = 3)
b_mult.grid(row = 2, column = 3)
b_subt = Button(window, text = '-', width = 7, height = 3)
b_subt.grid(row = 3, column = 3)
b_add = Button(window, text = '+', width = 7, height = 3)
b_add.grid(row = 4, column = 3)
b_equal = Button(window, text = '=', width = 7, height = 3)
b_equal.grid(row = 5, column = 3, pady = (0, 10))
#numbers
b_9 = Button(window, text = '9', width = 7, height = 3, command = lambda: click(9))
b_9.grid(row = 2, column = 2, padx = (10, 0), pady = 10)
b_8 = Button(window, text = '8', width = 7, height = 3, command = lambda: click(8))
b_8.grid(row = 2, column = 1)
b_7 = Button(window, text = '7', width = 7, height = 3, command = lambda: click(7))
b_7.grid(row = 2, column = 0, padx = 10)
b_6 = Button(window, text = '6', width = 7, height = 3, command = lambda: click(6))
b_6.grid(row = 3, column = 2, padx = (10, 0))
慕哥9229398
子衿沉夜
相关分类