Entry Widget in Tkinter Example 2

 import tkinter as tk


def on_submit():

    value = entry.get()

    label.config(text="You entered: " + value)


# Create the main window

root = tk.Tk()

root.title("Entry Example")


# Create an Entry widget

entry = tk.Entry(root, width=30, bg="lightgrey", fg="black", font=("Helvetica", 12), bd=2, relief=tk.SOLID)

entry.pack(pady=10)


# Create a button to submit the entry

submit_btn = tk.Button(root, text="Submit", command=on_submit, bg="blue", fg="white", font=("Helvetica", 12), padx=10, pady=5)

submit_btn.pack()


# Create a label to display the entered value

label = tk.Label(root, text="", bg="white", fg="black", font=("Helvetica", 12))

label.pack(pady=10)


# Run the Tkinter event loop

root.mainloop()


Explanation:


  1. bg: Background color of the Entry widget.
  2. fg: Foreground color (text color) of the Entry widget.
  3. font: Font style and size of the text in the Entry widget.
  4. bd: Border width of the Entry widget.
  5. relief: Border decoration of the Entry widget (e.g., tk.SOLID, tk.SUNKEN, tk.RAISED, etc.).
  6. padx and pady: Padding in the x (horizontal) and y (vertical) directions for the button widget.


Comments