{"id":1342,"date":"2020-11-30T03:02:26","date_gmt":"2020-11-30T03:02:26","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=1342"},"modified":"2025-04-03T08:48:31","modified_gmt":"2025-04-03T08:48:31","slug":"tkinter-entry","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-entry\/","title":{"rendered":"Tkinter Entry"},"content":{"rendered":"\r\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the Tkinter <code>Entry<\/code> widget to create a textbox.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='introduction-to-tkinter-entry-widget'>Introduction to Tkinter Entry widget <a href=\"#introduction-to-tkinter-entry-widget\" class=\"anchor\" id=\"introduction-to-tkinter-entry-widget\" title=\"Anchor for Introduction to Tkinter Entry widget\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>The <code>Entry<\/code> widget allows you to create a simple textbox with a single text line. To create a textbox, you use the following steps:<\/p>\r\n\r\n\r\n\r\n<p>First, import <code>ttk<\/code> module from <code>tkinter<\/code>:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Second, create the <code>Entry<\/code> widget&#8217;s constructor:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">entry = ttk.Entry(master, **kw)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>In this syntax:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>The <code>master<\/code> is the parent <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-frame\/\">frame<\/a> or <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-window\/\">window<\/a>, on which you want to place the <code>Entry<\/code> widget.<\/li>\r\n\r\n\r\n\r\n<li>The <code>kw<\/code> is one or more keyword arguments you use to configure the widget.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p class=\"note\">Note that if you want to create a multiline textbox, you can use the <code><a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-text\/\">Text<\/a><\/code> widget.<\/p>\r\n\r\n\r\n\r\n<p>To get the current value of an <code>Entry<\/code> widget as a string, you use the <code>get()<\/code> method:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">entry.get()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>The following program shows how to create an <code>Entry<\/code> widget and display it on the main window:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\r\n<span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk\r\n\r\nroot = tk.Tk()\r\nroot.geometry(<span class=\"hljs-string\">'300x200'<\/span>)\r\nroot.title(<span class=\"hljs-string\">'Entry Widget Demo'<\/span>)\r\n\r\n\r\nname_entry = ttk.Entry(root)\r\nname_entry.pack()\r\n\r\n\r\nroot.mainloop()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"306\" height=\"236\" class=\"wp-image-7414\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-widget-demo.png\" alt=\"tkinter entry widget demo\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-widget-demo.png 306w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-widget-demo-300x231.png 300w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='setting-the-focus'>Setting the focus <a href=\"#setting-the-focus\" class=\"anchor\" id=\"setting-the-focus\" title=\"Anchor for Setting the focus\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>To enhance user experience, you can move the focus to the first <code>Entry<\/code> widget after the window appears. Once the <code>Entry<\/code> widget has focus, it&#8217;s ready to accept the user input.<\/p>\r\n\r\n\r\n\r\n<p>You use the <code>focus()<\/code> method of the <code>Entry<\/code> widget to set the focus to a particular entry:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\r\n<span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk\r\n\r\nroot = tk.Tk()\r\nroot.geometry(<span class=\"hljs-string\">'300x200'<\/span>)\r\nroot.title(<span class=\"hljs-string\">'Entry Widget Demo'<\/span>)\r\n\r\n\r\nname_entry = ttk.Entry(root)\r\nname_entry.pack(pady=<span class=\"hljs-number\">5<\/span>)\r\nname_entry.focus()\r\n\r\nemail_entry = ttk.Entry(root)\r\nemail_entry.pack(pady=<span class=\"hljs-number\">5<\/span>)\r\n\r\nroot.mainloop()\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"306\" height=\"236\" class=\"wp-image-7416\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-widget-with-focus.png\" alt=\"tkinter entry widget with focus\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-widget-with-focus.png 306w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-widget-with-focus-300x231.png 300w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>How the program works:<\/p>\r\n\r\n\r\n\r\n<p>First, create two <code>Entry<\/code> widgets <code>name_entry<\/code> and <code>email_entry<\/code>.<\/p>\r\n\r\n\r\n\r\n<p>Second, create a padding between the first and second <code>Entry<\/code> widgets, we set the <code>pady<\/code> to 5 in the pack() method:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">name_entry.pack(pady=5)<\/code><\/span><\/pre>\r\n\r\n\r\n<p>Third, set the focus on the <code>name_widget<\/code> by calling the <code>focus()<\/code> method:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">name_entry<\/span><span class=\"hljs-selector-class\">.focus<\/span>()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Typically, you use a Label widget with an Entry widget to make the UI more clear:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\r\n<span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk\r\n\r\nroot = tk.Tk()\r\nroot.geometry(<span class=\"hljs-string\">'300x200'<\/span>)\r\nroot.title(<span class=\"hljs-string\">'Entry Widget Demo'<\/span>)\r\n\r\n\r\nname_label = ttk.Label(root, text=<span class=\"hljs-string\">'Name:'<\/span>)\r\nname_label.pack(pady=<span class=\"hljs-number\">2<\/span>)\r\n\r\nname_entry = ttk.Entry(root)\r\nname_entry.pack(pady=<span class=\"hljs-number\">5<\/span>)\r\nname_entry.focus()\r\n\r\n\r\nemail_label = ttk.Label(root, text=<span class=\"hljs-string\">'Email:'<\/span>)\r\nemail_label.pack(pady=<span class=\"hljs-number\">2<\/span>)\r\n\r\nemail_entry = ttk.Entry(root)\r\nemail_entry.pack(pady=<span class=\"hljs-number\">5<\/span>)\r\n\r\nroot.mainloop()\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"306\" height=\"236\" class=\"wp-image-7417\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-widgets-with-labels.png\" alt=\"\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-widgets-with-labels.png 306w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-widgets-with-labels-300x231.png 300w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>Note that you&#8217;ll learn how to make a nicer and more usable layout in the <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-pack\/\">pack<\/a> and <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-grid\/\">grid<\/a> tutorial.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='entering-sensitive-information'>Entering sensitive information <a href=\"#entering-sensitive-information\" class=\"anchor\" id=\"entering-sensitive-information\" title=\"Anchor for Entering sensitive information\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>To hide sensitive information on the <code>Entry<\/code> widget, e.g., a password, you can use the <code>show<\/code> option.<\/p>\r\n\r\n\r\n\r\n<p>The following creates a password entry so that when you enter a password, it doesn&#8217;t show the actual characters but the asterisks (<code>*<\/code>) specified in the <code>show<\/code> option:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">password_entry = ttk.Entry(root, show=<span class=\"hljs-string\">'*'<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>The following program illustrates how to create a new Entry for entering a password:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\r\n<span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk\r\n\r\nroot = tk.Tk()\r\nroot.geometry(<span class=\"hljs-string\">'300x200'<\/span>)\r\nroot.title(<span class=\"hljs-string\">'Entry Widget Demo'<\/span>)\r\n\r\n\r\npassword_label = ttk.Label(root, text=<span class=\"hljs-string\">'Password:'<\/span>)\r\npassword_label.pack(pady=<span class=\"hljs-number\">5<\/span>)\r\n\r\npassword_entry = ttk.Entry(root, show=<span class=\"hljs-string\">\"*\"<\/span>)\r\npassword_entry.pack(pady=<span class=\"hljs-number\">5<\/span>)\r\n\r\nroot.mainloop()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"306\" height=\"236\" class=\"wp-image-7418\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-password.png\" alt=\"tkinter entry password\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-password.png 306w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-entry-password-300x231.png 300w\" sizes=\"auto, (max-width: 306px) 100vw, 306px\" \/><\/figure>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='two-way-binding-with-a-stringvar-object'>Two-way binding with a StringVar object <a href=\"#two-way-binding-with-a-stringvar-object\" class=\"anchor\" id=\"two-way-binding-with-a-stringvar-object\" title=\"Anchor for Two-way binding with a StringVar object\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>Typically, you associate the current value of an <code>Entry<\/code> widget with a <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-stringvar\/\">StringVar<\/a> object via the <code>textvariable<\/code> parameter:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">text_var = tk.StringVar()\r\ntextbox = ttk.Entry(root, textvariable=text_var)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>In this syntax:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>First, create a new instance of the <code>StringVar<\/code> class. The <code>text_var<\/code> will hold a string value.<\/li>\r\n\r\n\r\n\r\n<li>Second, associate the <code>StringVar<\/code> object with an <code>Entry<\/code> widget by assigning the <code>StringVar<\/code> object to the <code>textvariable<\/code> .<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>After linking a <code>StringVar<\/code> object with an <code>Entry<\/code> widget, you can track and change the current value of the <code>Entry<\/code> widget via the <code>StringVar<\/code> object.<\/p>\r\n\r\n\r\n\r\n<p>On the other hand, if you change the value in the <code>Entry<\/code> widget, the change will be reflected in the value of the <code>StringVar<\/code> object.<\/p>\r\n\r\n\r\n\r\n<p>This is called <strong>two-way binding<\/strong> between a <code>StringVar<\/code> object and the <code>Entry<\/code> widget.<\/p>\r\n\r\n\r\n\r\n<p>To get the current value of the <code>Entry<\/code> widget, you can call the <code>get()<\/code> method of the <code>StringVar<\/code> object as follows:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">text_var.<span class=\"hljs-keyword\">get<\/span>()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>If you want to execute a function automatically when the value of the <code>Entry<\/code> changes, you can use the <code>trace_add()<\/code> method of the <code>StringVar<\/code> object:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">text_var.trace_add(<span class=\"hljs-string\">'write'<\/span>, callback)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Besides the <code>'write'<\/code> event, the <code>StringVar<\/code> supports the <code>'read'<\/code> and <code>'unset'<\/code> event.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='tracing-text-changes'>Tracing text changes <a href=\"#tracing-text-changes\" class=\"anchor\" id=\"tracing-text-changes\" title=\"Anchor for Tracing text changes\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<p>The following program shows how to track text changes in an <code>Entry<\/code> widget using a <code>StringVar<\/code> object:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\r\n<span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk\r\n\r\n\r\nroot = tk.Tk()\r\nroot.title(<span class=\"hljs-string\">'Tracing Text'<\/span>)\r\nroot.geometry(\"250x100\")\r\n\r\n\r\nname_var = tk.StringVar()\r\nname_entry = ttk.Entry(root, textvariable=name_var)\r\nname_entry.pack()\r\nname_entry.focus()\r\n\r\n\r\noutput_label = ttk.Label(root)\r\noutput_label.pack()\r\n\r\nname_var.trace_add(\r\n    \"write\", \r\n    lambda *args: output_label.config(<span class=\"hljs-type\">text<\/span>=name_var.<span class=\"hljs-keyword\">get<\/span>().upper())\r\n)\r\n\r\nroot.mainloop()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Output:<\/p>\r\n\r\n\r\n<div class=\"wp-block-image\">\r\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"366\" height=\"195\" class=\"wp-image-7367\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/Tkinter-Entry-Tracing-Text.gif\" alt=\"Tkinter Entry Tracing Text\" \/><\/figure>\r\n<\/div>\r\n\r\n\r\n<p>First, create <code>StringVar<\/code> object:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-14\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">name_var = tk.StringVar()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-14\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Second, link the <code>StringVar<\/code> object with the <code>Entry<\/code> widget:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-15\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">name_entry = ttk.Entry(root, textvariable=name_var)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-15\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<p>Third, execute a <a href=\"https:\/\/www.pythontutorial.net\/python-basics\/python-lambda-expressions\/\">lambda expression<\/a> when the text of the <code>Entry<\/code> widget changes. The lambda expression converts the text of the Entry widget to uppercase and sets it to the output label:<\/p>\r\n\r\n\r\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-16\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\">name_var.trace_add(\r\n    \"write\", \r\n    lambda *args: output_label.config(<span class=\"hljs-type\">text<\/span>=name_var.<span class=\"hljs-keyword\">get<\/span>().upper())\r\n)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-16\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\r\n\r\n\r\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li>Use the <code>ttk.Entry<\/code> widget to create a textbox.<\/li>\r\n\r\n\r\n\r\n<li>Use the <code>show<\/code> option to create a password entry.<\/li>\r\n\r\n\r\n\r\n<li>Track and change the current value of an Entry widget via a <code>StringVar<\/code> object.<\/li>\r\n<\/ul>\r\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1342\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-entry\/\"\n\t\t\t\tdata-post-title=\"Tkinter Entry\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1342\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-entry\/\"\n\t\t\t\tdata-post-title=\"Tkinter Entry\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to use the Tkinter Entry widget to create a textbox.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1232,"menu_order":8,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1342","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1342","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/comments?post=1342"}],"version-history":[{"count":5,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1342\/revisions"}],"predecessor-version":[{"id":7440,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1342\/revisions\/7440"}],"up":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1232"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=1342"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}