{"id":374,"date":"2019-01-30T23:43:00","date_gmt":"2019-01-31T07:43:00","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=374"},"modified":"2021-11-12T15:28:55","modified_gmt":"2021-11-12T23:28:55","slug":"tkinter-pack-geometry-manager","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2019\/01\/tkinter-pack-geometry-manager\/","title":{"rendered":"#53 Tkinter pack geometry manager"},"content":{"rendered":"<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport os\r\nfrom tkinter import *\r\nos.chdir(r'D:\\projects\\wordpress\\ex53')\r\nroot = Tk()\r\nButton(root,text=&quot;A&quot;).pack(side=LEFT,expand=YES,fill=Y)\r\nButton(root,text=&quot;B&quot;).pack(side=TOP,expand=YES,fill=BOTH)\r\nButton(root,text=&quot;C&quot;).pack(side=RIGHT,expand=YES,fill=NONE,anchor=NE)\r\nButton(root,text=&quot;D&quot;).pack(side=LEFT,expand=NO,fill=Y)\r\nButton(root,text=&quot;E&quot;).pack(side=TOP,expand=NO,fill=BOTH)\r\nButton(root,text=&quot;F&quot;).pack(side=RIGHT,expand=NO,fill=NONE)\r\nButton(root,text=&quot;G&quot;).pack(side=BOTTOM,expand=YES,fill=Y)\r\nButton(root,text=&quot;H&quot;).pack(side=TOP,expand=NO,fill=BOTH)\r\nButton(root,text=&quot;I&quot;).pack(side=RIGHT,expand=NO)\r\nButton(root,text=&quot;J&quot;).pack(anchor=SE)\r\nroot.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\/2019\/01\/example63.png?resize=140%2C169&#038;ssl=1\" alt=\"example63\" width=\"140\" height=\"169\" class=\"alignnone size-full wp-image-375\"\/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>import os from tkinter import * os.chdir(r&#8217;D:\\projects\\wordpress\\ex53&#8242;) root = Tk() Button(root,text=&quot;A&quot;).pack(side=LEFT,expand=YES,fill=Y) Button(root,text=&quot;B&quot;).pack(side=TOP,expand=YES,fill=BOTH) Button(root,text=&quot;C&quot;).pack(side=RIGHT,expand=YES,fill=NONE,anchor=NE) Button(root,text=&quot;D&quot;).pack(side=LEFT,expand=NO,fill=Y) Button(root,text=&quot;E&quot;).pack(side=TOP,expand=NO,fill=BOTH) Button(root,text=&quot;F&quot;).pack(side=RIGHT,expand=NO,fill=NONE) Button(root,text=&quot;G&quot;).pack(side=BOTTOM,expand=YES,fill=Y) Button(root,text=&quot;H&quot;).pack(side=TOP,expand=NO,fill=BOTH) Button(root,text=&quot;I&quot;).pack(side=RIGHT,expand=NO) Button(root,text=&quot;J&quot;).pack(anchor=SE) root.mainloop()<\/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],"tags":[],"class_list":["post-374","post","type-post","status-publish","format-standard","hentry","category-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-62","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":1358,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/01\/133-create-vectors-and-planes-using-tcl-in-hypermesh-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2\/","url_meta":{"origin":374,"position":0},"title":"#258 Tk example","author":"gantovnik","date":"2022-01-06","format":false,"excerpt":"Example: [code language=\"python\"] wm withdraw . set w [toplevel .t] wm title .t {Tk Code Example} set m [menu $w.menubar -tearoff 0] $m add cascade -label File -menu [menu $m.file] $m.file add command -label Quit -command exit $m add cascade -label Help -menu [menu $m.help] $m.help add command -label Index\u2026","rel":"","context":"In &quot;tcl&quot;","block_context":{"text":"tcl","link":"https:\/\/gantovnik.com\/bio-tips\/category\/tcl\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/01\/2022-01-06_015252.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":828,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/145-method-create_text-in-tkinter\/","url_meta":{"origin":374,"position":1},"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":822,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/143-colors-in-tkinter\/","url_meta":{"origin":374,"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":819,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/142-method-create_line-in-tkinter\/","url_meta":{"origin":374,"position":3},"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":825,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/01\/144-shapes-in-tkinter\/","url_meta":{"origin":374,"position":4},"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":502,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/05\/creating-a-python-3-tkinter-hello-world\/","url_meta":{"origin":374,"position":5},"title":"#74 Creating a Python 3 Tkinter Hello World","author":"gantovnik","date":"2020-05-05","format":false,"excerpt":"Creating a Python 3 Tkinter Hello World [code language=\"python\"] from tkinter import * from tkinter.ttk import * root = Tk() label = Label(root, text=\"Hello World\") label.pack() root.mainloop() [\/code]","rel":"","context":"In &quot;python&quot;","block_context":{"text":"python","link":"https:\/\/gantovnik.com\/bio-tips\/category\/python\/"},"img":{"alt_text":"2020-05-05_233237","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2020\/05\/2020-05-05_233237.png?resize=350%2C200","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/374","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=374"}],"version-history":[{"count":0,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/374\/revisions"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=374"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=374"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=374"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}