{"id":828,"date":"2021-01-02T21:57:26","date_gmt":"2021-01-03T05:57:26","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=828"},"modified":"2021-02-09T15:21:25","modified_gmt":"2021-02-09T23:21:25","slug":"145-method-create_text-in-tkinter","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/145-method-create_text-in-tkinter\/","title":{"rendered":"#145 Method create_text in tkinter"},"content":{"rendered":"<p>#145 Method create_text in tkinter<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n#!\/usr\/bin\/env python3\r\nfrom tkinter import Tk, Canvas, Frame, BOTH, W\r\n\r\nclass Example(Frame):\r\n    def __init__(self):\r\n        super().__init__()\r\n        self.initUI()\r\n\r\n    def initUI(self):\r\n        self.master.title(&quot;Method create_text in tkinter&quot;)\r\n        self.pack(fill=BOTH, expand=1)\r\n        canvas = Canvas(self)\r\n        canvas.create_text(20, 30, anchor=W, font=&quot;Comix&quot;, text=&quot;First line&quot;)\r\n        canvas.create_text(20, 60, anchor=W, font=&quot;Comix&quot;, text=&quot;Second line&quot;)\r\n        canvas.create_text(20, 130, anchor=W, font=&quot;Comix&quot;, text=&quot;Third line&quot;)\r\n        canvas.create_text(20, 160, anchor=W, font=&quot;Comix&quot;, text=&quot;Fourth line&quot;)\r\n        canvas.pack(fill=BOTH, expand=1)\r\n\r\ndef main():\r\n    root = Tk()\r\n    ex = Example()\r\n    root.geometry(&quot;420x250+300+300&quot;)\r\n    root.mainloop()\r\n\r\nif __name__ == '__main__':\r\n    main()\r\n<\/pre>\n<p><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/01\/ex145.png?resize=422%2C282\" alt=\"\" width=\"422\" height=\"282\" class=\"alignnone size-full wp-image-829\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#145 Method create_text in tkinter #!\/usr\/bin\/env python3 from tkinter import Tk, Canvas, Frame, BOTH, W class Example(Frame): def __init__(self): super().__init__() self.initUI() def initUI(self): self.master.title(&quot;Method create_text in tkinter&quot;) self.pack(fill=BOTH, expand=1) canvas = Canvas(self) canvas.create_text(20, 30, anchor=W, font=&quot;Comix&quot;, text=&quot;First line&quot;) canvas.create_text(20, 60, anchor=W, font=&quot;Comix&quot;, text=&quot;Second line&quot;) canvas.create_text(20, 130, anchor=W, font=&quot;Comix&quot;, text=&quot;Third line&quot;) canvas.create_text(20, 160, anchor=W, font=&quot;Comix&quot;, text=&quot;Fourth [&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-828","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-dm","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":819,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/142-method-create_line-in-tkinter\/","url_meta":{"origin":828,"position":0},"title":"#142 Method create_line in tkinter","author":"gantovnik","date":"2021-01-02","format":false,"excerpt":"#142 Method create_line in tkinter [code language=\"python\"] #!\/usr\/bin\/env python3 from tkinter import Tk, Canvas, Frame, BOTH class Example(Frame): def __init__(self): super().__init__() self.initUI() def initUI(self): self.master.title(\"Method create_line\") self.pack(fill=BOTH, expand=1) canvas = Canvas(self) canvas.create_line(15, 25, 200, 25) canvas.create_line(300, 35, 300, 200, dash=(4, 2)) canvas.create_line(320, 35, 350, 200, dash=(4, 2)) canvas.create_line(55, 85, 155,\u2026","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\/2021\/01\/ex142.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":822,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/143-colors-in-tkinter\/","url_meta":{"origin":828,"position":1},"title":"#143 Colors in tkinter","author":"gantovnik","date":"2021-01-02","format":false,"excerpt":"#143 Colors in tkinter [code language=\"python\"] #!\/usr\/bin\/env python3 from tkinter import Tk, Canvas, Frame, BOTH class Example(Frame): def __init__(self): super().__init__() self.initUI() def initUI(self): self.master.title(\"Colors in tkinter\") self.pack(fill=BOTH, expand=1) canvas = Canvas(self) canvas.create_rectangle(30, 10, 120, 80, outline=\"#fb0\", fill=\"#fb0\") canvas.create_rectangle(150, 10, 240, 80, outline=\"#f50\", fill=\"#f50\") canvas.create_rectangle(270, 10, 370, 80, outline=\"#05f\", fill=\"#05f\") canvas.pack(fill=BOTH,\u2026","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\/2021\/01\/ex143.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":825,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/144-shapes-in-tkinter\/","url_meta":{"origin":828,"position":2},"title":"#144 Shapes in tkinter","author":"gantovnik","date":"2021-01-02","format":false,"excerpt":"#144 Shapes in tkinter [code language=\"python\"] #!\/usr\/bin\/env python3 from tkinter import Tk, Canvas, Frame, BOTH class Example(Frame): def __init__(self): super().__init__() self.initUI() def initUI(self): self.master.title(\"Shapes in tkinter\") self.pack(fill=BOTH, expand=1) canvas = Canvas(self) canvas.create_oval(10, 10, 80, 80, outline=\"#080808\", fill=\"#1f1\", width=2) canvas.create_oval(110, 10, 210, 80, outline=\"#080808\", fill=\"#1f1\", width=2) canvas.create_rectangle(230, 10, 290, 60, outline=\"#080808\",\u2026","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\/2021\/01\/2021-01-02_210714.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":505,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/creating-a-better-version-of-python-3-tkinter-hello-world\/","url_meta":{"origin":828,"position":3},"title":"#75 Creating a better version of Python 3 Tkinter Hello World","author":"gantovnik","date":"2020-05-06","format":false,"excerpt":"Creating a better version of Python 3 Tkinter Hello World [code language=\"python\"] import tkinter as tk from tkinter import ttk class HelloView(tk.Frame): \"\"\"A friendly little module\"\"\" def __init__(self, parent, *args, **kwargs): super().__init__(parent, *args, **kwargs) self.name = tk.StringVar() self.hello_string = tk.StringVar() self.hello_string.set(\"Hello World\") name_label = ttk.Label(self, text=\"Name:\") name_entry = ttk.Entry(self, textvariable=self.name)\u2026","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_000413.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":374,"url":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/tkinter-pack-geometry-manager\/","url_meta":{"origin":828,"position":4},"title":"#53 Tkinter pack geometry manager","author":"gantovnik","date":"2019-01-30","format":false,"excerpt":"[code language=\"python\"] import os from tkinter import * os.chdir(r'D:\\projects\\wordpress\\ex53') root = Tk() Button(root,text=\"A\").pack(side=LEFT,expand=YES,fill=Y) Button(root,text=\"B\").pack(side=TOP,expand=YES,fill=BOTH) Button(root,text=\"C\").pack(side=RIGHT,expand=YES,fill=NONE,anchor=NE) Button(root,text=\"D\").pack(side=LEFT,expand=NO,fill=Y) Button(root,text=\"E\").pack(side=TOP,expand=NO,fill=BOTH) Button(root,text=\"F\").pack(side=RIGHT,expand=NO,fill=NONE) Button(root,text=\"G\").pack(side=BOTTOM,expand=YES,fill=Y) Button(root,text=\"H\").pack(side=TOP,expand=NO,fill=BOTH) Button(root,text=\"I\").pack(side=RIGHT,expand=NO) Button(root,text=\"J\").pack(anchor=SE) root.mainloop() [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"example63","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2019\/01\/example63.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1025,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/11\/182-feet-to-meter-converter-using-python-tkinter\/","url_meta":{"origin":828,"position":5},"title":"#182 Feet to meter converter using python tkinter","author":"gantovnik","date":"2021-11-04","format":false,"excerpt":"#182 Feet to meter converter using python tkinter [code language=\"python\"] from tkinter import * from tkinter import ttk def calculate(*args): try: value = float(feet.get()) meters.set(int(0.3048 * value * 10000.0 + 0.5)\/10000.0) except ValueError: pass root = Tk() root.title(\"Feet to meters converter\") mainframe = ttk.Frame(root, padding=\"3 3 12 12\") mainframe.grid(column=0, row=0,\u2026","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\/2021\/11\/ex182.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/828","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=828"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/828\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}