How to make value from button be displayed onto tkinter, when clicked rather than shell? How to make value from button be displayed onto tkinter, when clicked rather than shell? tkinter tkinter

How to make value from button be displayed onto tkinter, when clicked rather than shell?


You can access the text of the Label via the configure method like this:

from tkinter import *Value1 = 8.75Value2 = 6.25Value3 = int(7.00)class BasePrice():    def __init__(self):        window = Tk() # Creates a window        window.title("Price Calculator")        window.geometry('640x480')        btValue2 = Button(window,  text = "Value 2", fg = "blue", command = self.Value2).place(            x = 20, y = 20)        btValue1 = Button(window, text = "Value 1", fg = "blue", command = self.Value1).place(            x = 20, y = 60)        btValue3 = Button (window, text = "Value 3", fg = "blue", command = self.Value3).place(            x = 20, y = 100)        self.temp = Label(window, text = "Value: ", fg = "Green")        self.temp.place(x = 400, y = 100)        window.mainloop() # Create an event loop    def Value2(self):        print("Price: ", Value2)        self.temp.configure(text="Value: %s" % Value2)    def Value1(self):        print("Price: ", Value1)        self.temp.configure(text="Value: %s" % Value1)    def Value3(self):        print("Price: ", Value3)        self.temp.configure(text="Value: %s" % Value3)BasePrice() # Create an object to invoke __init__method

To add multiple values you could do something like this:

old = self.temp.cget("text")self.temp.configure(text="%s, %s" % (old, ValueX))