Using Entry in Python - The Advantages of Learning Python Programming for Beginners: A Comprehensive Guide

Latest

Dive into the world of Python programming with our comprehensive resources

Music

logo

Wednesday, December 28, 2022

Using Entry in Python

 

In this article, we will see the use of the Entry object in Python.  For windows application we need to add tkinter to our form.


import tkinter as tk

 

We define two entries named e1 and e2 inside the function.  Here, the name and surname are entered by using the insert property of the entry. The entered name and surname information is printed on the console by clicking the button. With the grid property of the entry, the position of the row and column is determined.

 


 

 

 

 

 

 

Figure 1

 

python_entry.py

 

import tkinter as tk

 

root = tk.Tk()

root.title("Entry example..bs")

root.geometry("360x100")

 

def show_entry_fields():

    print("First Name: %s\nLast Name: %s" % (e1.get(), e2.get()))

    e1.delete(0, tk.END)

    e2.delete(0, tk.END)

 

 

tk.Label(root, text="First Name", width=8,font=("arial,12,normal")).grid(row=0)

tk.Label(root, text="Last Name", width=8,font=("arial,12,normal")).grid(row=1)

 

e1 = tk.Entry(root,font=("arial,12,normal"))

e2 = tk.Entry(root,font=("arial,12,normal"))

e1.insert(8, "Bahadir")

e2.insert(8, "Sahin")

 

e1.grid(row=0, column=1)

e2.grid(row=1, column=1)

 

tk.Button(root,

          text='Exit',

          command=root.quit, width=18,font=("arial,12,normal")).grid(row=3,

                                    column=0,

                                    sticky=tk.W,

                                    pady=4)

tk.Button(root, text='Show', command=show_entry_fields,width=18,font=("arial,12,normal")).grid(row=3,

                                                               column=1,

                                                               sticky=tk.W,

                                                               pady=4)

 

root.mainloop()

 

tk.mainloop()

 

I have come to the end of this article. See you in my next article. Happy coding. Bahadir Sahin

No comments:

Post a Comment

Featured post

Python Introduction

What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built ...