I would like to update a label once I press one of the buttons.
Here is my code - I added a label (caled label1), now I have two issues:
- It presents some gibberish
- How do I update the label with text right when the user is pressing the Browse button?
from tkinter import *
import threading
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
def init_window(self):
self.var = IntVar()
self.master.title("GUI")
self.pack(fill=BOTH, expand=1)
quitButton = Button(self, text="Exit", command=self.client_exit)
startButton = Button(self, text="Browse", command=self.start_Button)
label1 = Label(self, text=self.lable_1)
quitButton.grid(row=0, column=0)
startButton.grid(row=0, column=2)
label1.grid(row=1, column=0)
def client_exit(self):
exit()
def lable_1(self):
print('starting')
def start_Button(self):
def f():
print('Program is starting')
t = threading.Thread(target=f)
t.start()
root = Tk()
root.geometry("250x50")
app = Window(root)
root.title("My Program")
root.mainloop()
self.label1to get access toLabel. BTW:self.label_1is function and there is no sense to use it as text -text=self.label_1. BTW:printonly sends text on screen - it doesn't assign value to variable - usereturninstead ofprintin functionlabel_1and then you can dotext=self.lable_1()- with()at the end. - furasroot.after(milisecond, function_name)to run function periodically and maybe you will no need threads. - furas