{"id":822,"date":"2021-01-02T02:06:45","date_gmt":"2021-01-02T10:06:45","guid":{"rendered":"http:\/\/gantovnik.com\/bio-tips\/?p=822"},"modified":"2021-01-02T02:06:45","modified_gmt":"2021-01-02T10:06:45","slug":"143-colors-in-tkinter","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/143-colors-in-tkinter\/","title":{"rendered":"#143 Colors in tkinter"},"content":{"rendered":"<p>#143 Colors 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;Colors in tkinter&quot;)\r\n        self.pack(fill=BOTH, expand=1)\r\n        canvas = Canvas(self)\r\n        canvas.create_rectangle(30, 10, 120, 80,\r\n            outline=&quot;#fb0&quot;, fill=&quot;#fb0&quot;)\r\n        canvas.create_rectangle(150, 10, 240, 80,\r\n            outline=&quot;#f50&quot;, fill=&quot;#f50&quot;)\r\n        canvas.create_rectangle(270, 10, 370, 80,\r\n            outline=&quot;#05f&quot;, fill=&quot;#05f&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;400x100+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\/ex143.png?resize=402%2C132\" alt=\"\" width=\"402\" height=\"132\" class=\"alignnone size-full wp-image-823\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/01\/ex143.png?w=402&amp;ssl=1 402w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/01\/ex143.png?resize=300%2C99&amp;ssl=1 300w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2021\/01\/ex143.png?resize=400%2C132&amp;ssl=1 400w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>#143 Colors 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;Colors in tkinter&quot;) self.pack(fill=BOTH, expand=1) canvas = Canvas(self) canvas.create_rectangle(30, 10, 120, 80, outline=&quot;#fb0&quot;, fill=&quot;#fb0&quot;) canvas.create_rectangle(150, 10, 240, 80, outline=&quot;#f50&quot;, fill=&quot;#f50&quot;) canvas.create_rectangle(270, 10, 370, 80, outline=&quot;#05f&quot;, fill=&quot;#05f&quot;) canvas.pack(fill=BOTH, expand=1) def main(): root = Tk() ex [&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_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":"","jetpack_post_was_ever_published":false},"categories":[2,26],"tags":[],"class_list":["post-822","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-dg","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":825,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/144-shapes-in-tkinter\/","url_meta":{"origin":822,"position":0},"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":819,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/142-method-create_line-in-tkinter\/","url_meta":{"origin":822,"position":1},"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":828,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/145-method-create_text-in-tkinter\/","url_meta":{"origin":822,"position":2},"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":505,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/creating-a-better-version-of-python-3-tkinter-hello-world\/","url_meta":{"origin":822,"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":822,"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":567,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/06\/82\/","url_meta":{"origin":822,"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\/822","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=822"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/822\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}