[英]How do I keep label text side by side with label value in tkinter
I am trying to keep the label text value: "This is the subtotal" next to subtotal value.我试图保留 label 文本值:“这是小计”旁边的小计值。 Meaning:意义:
If I were to click on the "Calulate Subtotal" Button the text "This is the subtotal" should be to the right and the actual subtotal should be to the left.如果我点击“计算小计”按钮,文本“这是小计”应该在右边,实际小计应该在左边。 Currently, If I were to click on the "Calulate Subtotal" Button the text "this is the subtotal" disappears.目前,如果我点击“计算小计”按钮,“这是小计”的文本就会消失。 Can someone steer me in the right direction?有人可以引导我朝着正确的方向前进吗?
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()
You can simply change your getSubtotals
method to retain the current text of firstLabel
as the following:您可以简单地更改您的getSubtotals
方法以保留firstLabel
的当前文本,如下所示:
def getSubtotals(self):
self.firstLabel["text"] = self.firstLabel["text"] + str(55 * 10)
Couple of suggestions:几个建议:
firstLabel
.您可能想要创建另一个小部件来显示除firstLabel
之外的小计值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.