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:
bg
: Background color of the Entry widget.fg
: Foreground color (text color) of the Entry widget.font
: Font style and size of the text in the Entry widget.bd
: Border width of the Entry widget.relief
: Border decoration of the Entry widget (e.g.,tk.SOLID
,tk.SUNKEN
,tk.RAISED
, etc.).padx
andpady
: Padding in the x (horizontal) and y (vertical) directions for the button widget.
Comments
Post a Comment