{"id":563,"date":"2020-06-13T00:37:08","date_gmt":"2020-06-13T07:37:08","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=563"},"modified":"2020-06-13T00:37:08","modified_gmt":"2020-06-13T07:37:08","slug":"81-the-text-widget","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2020\/06\/81-the-text-widget\/","title":{"rendered":"#81 The Text widget"},"content":{"rendered":"<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport tkinter as tk\r\n\r\nparent = tk.Tk()\r\n# create the widget.  Make sure to save a reference.\r\nmytext = tk.Text(parent)\r\n\r\n# insert a string at the beginning\r\nmytext.insert('1.0', &quot;I love my text widget!&quot;)\r\n\r\n# insert a string into the current text\r\nmytext.insert('1.2', 'REALLY ')\r\n\r\n# get the whole string\r\nmytext.get('1.0', tk.END)\r\n\r\n# delete the last character.\r\n# Note that there is always a newline character\r\n# at the end of the input, so we backup 2 chars.\r\nmytext.delete('end - 2 chars')\r\n\r\nmytext.pack()\r\nparent.mainloop()\r\n<\/pre>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/06\/2020-06-13_003342.jpg?resize=259%2C123\" alt=\"\" width=\"259\" height=\"123\" class=\"alignnone size-full wp-image-564\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import tkinter as tk parent = tk.Tk() # create the widget. Make sure to save a reference. mytext = tk.Text(parent) # insert a string at the beginning mytext.insert(&#8216;1.0&#8217;, &quot;I love my text widget!&quot;) # insert a string into the current text mytext.insert(&#8216;1.2&#8217;, &#8216;REALLY &#8216;) # get the whole string mytext.get(&#8216;1.0&#8217;, tk.END) # delete the last [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2,26],"tags":[],"class_list":["post-563","post","type-post","status-publish","format-standard","hentry","category-python","category-tkinter"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-95","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":522,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/the-checkbutton-widget\/","url_meta":{"origin":563,"position":0},"title":"#80 The Checkbutton widget","author":"gantovnik","date":"2020-05-06","format":false,"excerpt":"The Checkbutton widget [code language=\"python\"] import tkinter as tk from tkinter import ttk parent = tk.Tk() my_boolean_var = tk.BooleanVar() my_checkbutton = ttk.Checkbutton( text=\"Check to make this option True\", variable=my_boolean_var ) my_checkbutton.pack() parent.mainloop() [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/05\/2020-05-06_015642.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":512,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/the-entry-widget\/","url_meta":{"origin":563,"position":1},"title":"#77 The Entry widget","author":"gantovnik","date":"2020-05-06","format":false,"excerpt":"The Entry widget [code language=\"python\"] import tkinter as tk from tkinter import ttk parent = tk.Tk() my_text_var = tk.StringVar() my_entry = ttk.Entry( parent, textvariable=my_text_var ) my_entry.pack() parent.mainloop() [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/05\/2020-05-06_014229.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":515,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/the-spinbox-widget\/","url_meta":{"origin":563,"position":2},"title":"#78 The Spinbox widget","author":"gantovnik","date":"2020-05-06","format":false,"excerpt":"The Spinbox widget [code language=\"python\"] import tkinter as tk from tkinter import ttk parent = tk.Tk() my_double_var = tk.DoubleVar() my_spinbox = tk.Spinbox( parent, from_=0.5, to=52.0, increment=.01, textvariable=my_double_var ) my_spinbox.pack() parent.mainloop() [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/05\/2020-05-06_014722.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":519,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/the-combobox-widget\/","url_meta":{"origin":563,"position":3},"title":"#79 The Combobox widget","author":"gantovnik","date":"2020-05-06","format":false,"excerpt":"The Combobox widget [code language=\"python\"] import tkinter as tk from tkinter import ttk parent = tk.Tk() my_string_var = tk.StringVar() combobox = ttk.Combobox( parent, textvariable=my_string_var, values=[\"Option 1\", \"Option 2\", \"Option 3\"] ) combobox.pack() parent.mainloop() [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/05\/2020-05-06_015402.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":508,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/the-button-widget\/","url_meta":{"origin":563,"position":4},"title":"#76 The Button widget","author":"gantovnik","date":"2020-05-06","format":false,"excerpt":"The Button widget [code language=\"python\"] import tkinter as tk from tkinter import ttk parent = tk.Tk() tvar = tk.StringVar() def swaptext(): tvar.set('There' if tvar.get() == 'Hi' else 'Hi') my_button = ttk.Button(parent, textvariable=tvar, command=swaptext) my_button.pack() parent.mainloop() [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/05\/2020-05-06_012455.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":567,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/06\/82\/","url_meta":{"origin":563,"position":5},"title":"#82 The Button widget","author":"gantovnik","date":"2020-06-13","format":false,"excerpt":"[code language=\"python\"] import tkinter as tk from tkinter import ttk parent = tk.Tk() tvar = tk.StringVar() def swaptext(): tvar.set('There' if tvar.get() == 'Hi' else 'Hi') my_button = ttk.Button(parent, textvariable=tvar, command=swaptext) my_button.pack() parent.mainloop() [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/06\/2020-06-13_010517.jpg?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/563","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=563"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/563\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=563"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=563"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=563"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}