Python Forum
[Tkinter] check if entry is null
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] check if entry is null
#2
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()
rwahdan likes this post
Reply


Messages In This Thread
check if entry is null - by rwahdan - Jun-25-2021, 03:39 PM
RE: check if entry is null - by Yoriz - Jun-25-2021, 03:55 PM
RE: check if entry is null - by rwahdan - Jun-25-2021, 04:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Transfer Toplevel window entry to root window entry with TKinter HBH 0 5,247 Jan-23-2020, 09:00 PM
Last Post: HBH
  [Tkinter] how to get the entry information using Entry.get() ? SamyPyth 2 4,303 Mar-18-2019, 05:36 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020