{"id":819,"date":"2021-01-02T01:14:24","date_gmt":"2021-01-02T09:14:24","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=819"},"modified":"2021-01-02T01:14:24","modified_gmt":"2021-01-02T09:14:24","slug":"142-method-create_line-in-tkinter","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/142-method-create_line-in-tkinter\/","title":{"rendered":"#142 Method create_line in tkinter"},"content":{"rendered":"<p>#142 Method create_line 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\r\n\r\nclass Example(Frame):\r\n\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_line&quot;)\r\n        self.pack(fill=BOTH, expand=1)\r\n        canvas = Canvas(self)\r\n        canvas.create_line(15, 25, 200, 25)\r\n        canvas.create_line(300, 35, 300, 200, dash=(4, 2))\r\n        canvas.create_line(320, 35, 350, 200, dash=(4, 2))\r\n        canvas.create_line(55, 85, 155, 85, 105, 180, 55, 85)\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;400x250+300+300&quot;)\r\n    root.mainloop()\r\n\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\/ex142.png?resize=402%2C282\" alt=\"\" width=\"402\" height=\"282\" class=\"alignnone size-full wp-image-820\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/01\/ex142.png?w=402&amp;ssl=1 402w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/01\/ex142.png?resize=300%2C210&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/01\/ex142.png?resize=400%2C282&amp;ssl=1 400w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#142 Method create_line in tkinter #!\/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(&quot;Method create_line&quot;) 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, 85, 105, 180, 55, 85) canvas.pack(fill=BOTH, expand=1) [&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-819","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-dd","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":828,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/145-method-create_text-in-tkinter\/","url_meta":{"origin":819,"position":0},"title":"#145 Method create_text in tkinter","author":"gantovnik","date":"2021-01-02","format":false,"excerpt":"#145 Method create_text in tkinter [code language=\"python\"] #!\/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(\"Method create_text in tkinter\") self.pack(fill=BOTH, expand=1) canvas = Canvas(self) canvas.create_text(20, 30, anchor=W, font=\"Comix\", text=\"First line\") canvas.create_text(20, 60, anchor=W, font=\"Comix\", text=\"Second line\") canvas.create_text(20, 130, anchor=W, font=\"Comix\",\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\/ex145.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":819,"position":1},"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":822,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/143-colors-in-tkinter\/","url_meta":{"origin":819,"position":2},"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":505,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/creating-a-better-version-of-python-3-tkinter-hello-world\/","url_meta":{"origin":819,"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":567,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/06\/82\/","url_meta":{"origin":819,"position":4},"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":[]},{"id":508,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/the-button-widget\/","url_meta":{"origin":819,"position":5},"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":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/819","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=819"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/819\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=819"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=819"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=819"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}