Jun-25-2021, 03:55 PM
Here is an example code that prints either
Entry has a value
or Entry is empty
import tkinter as tk from tkinter import ttk class TkApp(tk.Tk): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.entry = ttk.Entry(self) self.entry.pack(padx=5, pady=5) self.button = ttk.Button(self, text='Print', command=self.on_button) self.button.pack(pady=5) def on_button(self): entry_value = self.entry.get() print(f'Entry contains: {entry_value}') if entry_value: print('Entry has a value') else: print('Entry is empty') if __name__ == '__main__': app = TkApp() app.mainloop()