我不确定为什么它没有显示消息'开始计算'

问题描述 投票:0回答:1

我正在编写一个计算器应用程序并使用Tkinter和python 3.7。我目前陷入困境,因为当我尝试运行它时,一切正常,除了它没有在屏幕上显示“开始计算...”。有人能帮忙吗?

我试过调用最后使用的函数但是没有用。我不知道还有什么可以尝试的。

from tkinter import *

def btn(numbers):
    global operator
    operator = operator + str(numbers)

root = Tk()
root.title("Calculator")

operator = ''
txt_input = StringVar(value='Start Calculating...')

#========================Screen=======================
Display = Entry(root, fg='white', bg='white', 
    justify='right', bd=28, textvariable=txt_input)
Display.grid(columnspan=5, sticky='NSEW')

#=======================Row1==========================
b7 = Button(root, padx=30, pady=15, bd=8, fg='black', text='7', highlightbackground='white', highlightthickness=0.0001).grid(row=1, column=0, sticky='NSEW')
b8 = Button(root, padx=30, pady=15, bd=8, fg='black', text='8', highlightbackground='white', highlightthickness=0.0001).grid(row=1, column=1, sticky='NSEW')
b9 = Button(root, padx=30, pady=15, bd=8, fg='black', text='9', highlightbackground='white', highlightthickness=0.0001).grid(row=1, column=2, sticky='NSEW')
clear = Button(root, padx=30, pady=15, bd=8, fg='black', text='C', highlightbackground='green', highlightthickness=0.0001).grid(row=1, column=3, sticky='NSEW')

#=======================Row2==========================
b4 = Button(root, padx=30, pady=15, bd=8, fg='black', text='4', highlightbackground='white', highlightthickness=0.0001).grid(row=2, column=0, sticky='NSEW')
b5 = Button(root, padx=30, pady=15, bd=8, fg='black', text='5', highlightbackground='white', highlightthickness=0.0001).grid(row=2, column=1, sticky='NSEW')
b6 = Button(root, padx=30, pady=15, bd=8, fg='black', text='6', highlightbackground='white', highlightthickness=0.0001).grid(row=2, column=2, sticky='NSEW')
plus = Button(root, padx=30, pady=15, bd=8, fg='black', text='+', highlightbackground='orange', highlightthickness=0.0001).grid(row=2, column=3, sticky='NSEW')

#=======================Row3==========================
b1 = Button(root, padx=30, pady=15, bd=8, fg='black', text='1', highlightbackground='white', highlightthickness=0.0001).grid(row=3, column=0, sticky='NSEW')
b2 = Button(root, padx=30, pady=15, bd=8, fg='black', text='2', highlightbackground='white', highlightthickness=0.0001).grid(row=3, column=1, sticky='NSEW')
b3 = Button(root, padx=30, pady=15, bd=8, fg='black', text='3', highlightbackground='white', highlightthickness=0.0001).grid(row=3, column=2, sticky='NSEW')
minus = Button(root, padx=30, pady=15, bd=8, fg='black', text='-', highlightbackground='orange', highlightthickness=0.0001).grid(row=3, column=3, sticky='NSEW')

#=======================Row4==========================
b0 = Button(root, padx=30, pady=15, bd=8, fg='black', text='0', highlightbackground='white', highlightthickness=0.0001).grid(row=4, column=0, sticky='NSEW')
dot = Button(root, padx=30, pady=15, bd=8, fg='black', text='.', highlightbackground='orange', highlightthickness=0.0001).grid(row=4, column=1, sticky='NSEW')
div = Button(root, padx=30, pady=15, bd=8, fg='black', text='/', highlightbackground='orange', highlightthickness=0.0001).grid(row=4, column=2, sticky='NSEW')
times = Button(root, padx=30, pady=15, bd=8, fg='black', text='x', highlightbackground='orange', highlightthickness=0.0001).grid(row=4, column=3, sticky='NSEW')

#=======================Row5==========================
equals = Button(root, padx=95, pady=15, bd=8, fg='black', text='=', highlightbackground='green', highlightthickness=0.0001).grid(row=5, columnspan=2)
bracket1 = Button(root, padx=35, pady=15, bd=8, fg='black', text='(', highlightbackground='orange', highlightthickness=0.0001).grid(row=5, column=2)
bracket2 = Button(root, padx=38, pady=15, bd=8, fg='black', text=')', highlightbackground='orange', highlightthickness=0.0001).grid(row=5, column=3)

root.mainloop()
python python-3.x tkinter
1个回答
2
投票

你的问题是前景(文字)和背景颜色都是白色的,所以你不会看到任何文字。

作为旁注:要在条目中放置值,如果您不想将其与变量关联,也可以使用insert条目方法:

Display.insert(0, 'Start Calculating...')Display.insert(0, txt_input.get()) 0是条目(位置)在条目文本中要插入指定文本的位置,即将文本插入第0个位置 - 开头。

© www.soinside.com 2019 - 2024. All rights reserved.