Hello guys I need to check if this label empty or not empty:
If not empty active some button.
I get the filename from another method.
this is the code :
lb = Label(self, text="", background='white')
lb.config(text=excel_name)
Hello guys I need to check if this label empty or not empty:
If not empty active some button.
I get the filename from another method.
this is the code :
lb = Label(self, text="", background='white')
lb.config(text=excel_name)
Here is a simple app that demonstrates a button being activated or disabled based on whether a label's text is the empty string or not:
import tkinter as tk
class App(tk.Tk):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.lb = tk.Label(self)
self.lb.pack()
self.entry = tk.Entry(self)
self.entry.pack()
self.button = tk.Button(self, text="A button", command=lambda: print("Button pressed"))
self.button["state"] = tk.DISABLED
self.button.pack()
self.bind("<Return>", self.enter_pressed)
def enter_pressed(self, event):
self.lb.config(text=self.entry.get())
self.button["state"] = tk.NORMAL if self.lb["text"] else tk.DISABLED
app = App()
app.mainloop()
The window contains a label, then a text entry box, then a button. If you type text into the text entry box then press the enter key (return key), the label text is set to the text in the text box, and the button is set to either enabled or disabled depending on if the label text is empty or not.
The key line here is:
self.button["state"] = tk.NORMAL if self.lb["text"] else tk.DISABLED
This sets the button state to either tk.NORMAL
(enabled) or tk.DISABLED
depending on whether the label text (self.lb["text"]
) is the empty string or not.