Sunday, June 22, 2025
HomejQueryPython tkinter entry / single-line textual content field widget: 7 Examples

Python tkinter entry / single-line textual content field widget: 7 Examples


Creating single line textbox in Python utilizing tkinter library

To allow customers to enter single-line textual content in Python GUI primarily based utility, you might use the tkinter entry widget.

  • The entry widget permits single-line textual content.
  • For a number of line textual content entry, use the textual content widget.
  • A person can enter numbers, strings, and combined textual content as utilizing the entry widget of tkinter library.

Syntax of making an entry widget

w = Entry (mum or dad, choices)

Allow us to present you examples of making single line textbox with easy and completely different out there choices.

An instance of easy entry widget

On this instance, we are going to create a label that’s connected with the Entry widget. As you run this system, you will notice:

Enter your identify:

With the entry widget/textbox:



Output:

tkinter-entry-simple

Setting the background colour of entry field

By utilizing bg choice of the entry widget, you might set the background colour of the textbox.

It’s possible you’ll present a colour identify e.g. inexperienced, blue, pink, and many others., or a colour worth e.g. #FFF000.

See the instance under.

Code:



Output:

tkinter-entry-bg-color

Setting borders of textual content field by bd choice

The bd choice permits us to set the borders of the Entry textbox. The default worth is 2.

Within the instance under, we are going to set the border of two entry widgets. The primary is 5 px and the second is 10 pixels for the demo solely.

Python code:



Output:

tkinter-entry-borders

An instance of foreground colour/textual content colour

For setting the foreground colour (or textual content colour) of the entry widget, use the fg choice.

The default is black. Nevertheless, as we set the darkish background colour within the above examples, you might have considered trying a lighter colour of the textual content.

The instance under has two entry fields. One with the default black colour and the second is yellow colour for the foreground (fg) choice.

Code:



Output:

tkinter-entry-foregroun

Present entered textual content as * or another character – password subject

By utilizing present choice of the entry widget, you might show entered characters as the required character.

For instance, you wish to take the person password and show * for the entered character.

The instance under exhibits “^” for the primary entry subject and “*” for the second subject.

Code:



Output:

tkinter-entry-show

An instance of disabled entry fields

By utilizing state=DISABLED choice, the entry subject is seen as grayed-out aspect within the kind. The default worth of the state is NORMAL.

The instance under shows two entry fields. The primary is disabled and the opposite is regular.

Code:



Output:

tkinter-entry-Disabled

An instance of utilizing entry in a message field

On this instance, we are going to get the worth of the entry subject and show it within the tkinter message field.

For that, execute this system and enter textual content into the entry subject. After this, press the button and it’ll show the textual content of the entry in a message field.

Code:



Pattern output:

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments