我试图保留标签文本值:小计值旁边的“这是小计”。含义:
如果我要单击“计算小计”按钮,则文本“这是小计”应在右侧,而实际小计应在左侧。当前,如果我单击“计算小计”按钮,则“这是小计”文本将消失。有人可以指引我正确的方向吗?
try:
import Tkinter as tk
except:
import tkinter as tk
class GetInterfaceValues():
def __init__(self):
self.root = tk.Tk()
self.root.geometry('500x200')
self.button = tk.Button(self.root,
text='Calculate Subtotal',
command=self.getSubtotals)
self.button.pack()
self.firstLabel = tk.Label(self.root, text="This is the subtotal:")
self.firstLabel.pack()
self.root.mainloop()
def getSubtotals(self):
self.firstLabel["text"] = 55*10
app = GetInterfaceValues()
答案 0 :(得分:1)
您只需更改您的getSubtotals
方法即可保留firstLabel
的当前文本,如下所示:
def getSubtotals(self):
self.firstLabel["text"] = self.firstLabel["text"] + str(55 * 10)
建议对
firstLabel
以外的小计值。