{"id":1313,"date":"2020-11-29T03:19:58","date_gmt":"2020-11-29T03:19:58","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=1313"},"modified":"2025-04-02T13:39:29","modified_gmt":"2025-04-02T13:39:29","slug":"tkinter-place","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-place\/","title":{"rendered":"Tkinter Place"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn about the Tkinter <code>place<\/code> geometry manager to precisely position widgets within its container using the (x, y) coordinate system.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-tkinter-place-geometry-manager'>Introduction to Tkinter Place Geometry Manager <a href=\"#introduction-to-tkinter-place-geometry-manager\" class=\"anchor\" id=\"introduction-to-tkinter-place-geometry-manager\" title=\"Anchor for Introduction to Tkinter Place Geometry Manager\">#<\/a><\/h2>\n\n\n\n<p>The Tkinter <code>place<\/code> geometry manager allows you to specify the exact placement of a widget using either absolution or relative positioning. <\/p>\n\n\n\n<p>The placer geometry management gives you fine control over the positioning of widgets by allowing you to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Specify coordinates (x, y).<\/li>\n\n\n\n<li>Use relative positioning based on anchor points.<\/li>\n<\/ul>\n\n\n\n<p>To use the <code>place<\/code> geometry manager, you call the <code>place()<\/code> method on the widget like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">widget<\/span><span class=\"hljs-selector-class\">.place<\/span>(**<span class=\"hljs-selector-tag\">options<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='absolute-positioning'>Absolute positioning <a href=\"#absolute-positioning\" class=\"anchor\" id=\"absolute-positioning\" title=\"Anchor for Absolute positioning\">#<\/a><\/h3>\n\n\n\n<p>In absolute positioning, you specify the exact x and y coordinates of the widget using the x and y parameters:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">widget.place(x=50, y=50)<\/code><\/span><\/pre>\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-absolute.svg\" alt=\"tkinter place absolute\" class=\"wp-image-6828\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='relative-positioning'>Relative positioning <a href=\"#relative-positioning\" class=\"anchor\" id=\"relative-positioning\" title=\"Anchor for Relative positioning\">#<\/a><\/h3>\n\n\n\n<p>In relative positioning, you place the widget using the relative coordinates using <code>relx<\/code> and <code>rely<\/code> parameters:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-relative.svg\" alt=\"tkinter place relative\" class=\"wp-image-6827\"\/><\/figure>\n\n\n\n<p>For example, the following place the widget in the center of its parent:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">widget.place(relx=0.5, rely=0.5, anchor=CENTER)\n<\/code><\/span><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='width-and-height'>Width and height <a href=\"#width-and-height\" class=\"anchor\" id=\"width-and-height\" title=\"Anchor for Width and height\">#<\/a><\/h3>\n\n\n\n<p>The place geometry manager allows you to set the width and height of the widget via the <code>width<\/code> and <code>height<\/code> paramaters:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">widget.place(width=120, height=60)<\/code><\/span><\/pre>\n\n\n<p>Alternatively, you can use relative sizing concerning the parent container. For example, the following code sets the widget&#8217;s width and height to 50% of the parent&#8217;s dimensions:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">widget.place(relwidth=0.5, relheight=0.5)<\/code><\/span><\/pre>\n\n\n<p>The <code>relwidth<\/code> and <code>relheight<\/code> has a value of a floating-point number between 0.0 and 1.0. This value represents a fraction of the width and height of the parent container.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='anchor'>Anchor <a href=\"#anchor\" class=\"anchor\" id=\"anchor\" title=\"Anchor for Anchor\">#<\/a><\/h3>\n\n\n\n<p>The <code>anchor<\/code> parameter determines which part of the widget is positioned at the given coordinates.<\/p>\n\n\n\n<p>The <code>anchor<\/code> parameter accepts values such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>'n'<\/code>, <code>'ne'<\/code>, <code>'e'<\/code>, <code>'se'<\/code>, <code>'sw'<\/code>, <code>'w'<\/code>, <code>'nw'<\/code>: These constants represent the cardinal and intercardinal directions (north, northeast, east, southeast, south, southwest, west, northwest).<\/li>\n\n\n\n<li><code>'center'<\/code>: This value instructs the <code>place()<\/code> method to position the center of the widget at the specified coordinates.<\/li>\n<\/ul>\n\n\n\n<p>The default value of the anchor is <code>'nw'<\/code> which instructs the <code>place()<\/code> method to position the top left of the widget at the specified coordinates.<\/p>\n\n\n\n<p>For example, the following code places the widget in the center of the container widget:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">widget.place(relx=<span class=\"hljs-number\">0.5<\/span>, rely=<span class=\"hljs-number\">0.5<\/span>, anchor=<span class=\"hljs-string\">'center'<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='tkinter-place-geometry-manager-examples'>Tkinter place geometry manager examples <a href=\"#tkinter-place-geometry-manager-examples\" class=\"anchor\" id=\"tkinter-place-geometry-manager-examples\" title=\"Anchor for Tkinter place geometry manager examples\">#<\/a><\/h2>\n\n\n\n<p>Let&#8217;s take some examples of using the Tkinter place geometry manager.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='absolute-positioning-example'>Absolute positioning example <a href=\"#absolute-positioning-example\" class=\"anchor\" id=\"absolute-positioning-example\" title=\"Anchor for Absolute positioning example\">#<\/a><\/h3>\n\n\n\n<p>The following example uses the place geometry manager to place a label at (0,0) with a width of 60 and height of 120:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\n\nroot = tk.Tk()\nroot.title(<span class=\"hljs-string\">'Tkinter Place Geometry Manager'<\/span>)\nroot.geometry(<span class=\"hljs-string\">\"600x400\"<\/span>)\n\nlabel1 = tk.Label(master=root, text=<span class=\"hljs-string\">\"Place\"<\/span>,bg=<span class=\"hljs-string\">'red'<\/span>,fg=<span class=\"hljs-string\">'white'<\/span>)\nlabel1.place(x=<span class=\"hljs-number\">0<\/span>,y=<span class=\"hljs-number\">0<\/span>,width=<span class=\"hljs-number\">120<\/span>, height=<span class=\"hljs-number\">60<\/span>)\n\nroot.mainloop()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"446\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-absolute-position.png\" alt=\"tkinter place absolute position\" class=\"wp-image-6829\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-absolute-position.png 602w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-absolute-position-300x222.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='relative-positioning-example'>Relative positioning example <a href=\"#relative-positioning-example\" class=\"anchor\" id=\"relative-positioning-example\" title=\"Anchor for Relative positioning example\">#<\/a><\/h3>\n\n\n\n<p>The following program places a Label widget with its top-left corner at the center of the window:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\n\nroot = tk.Tk()\nroot.title(<span class=\"hljs-string\">'Tkinter Place Geometry Manager'<\/span>)\nroot.geometry(<span class=\"hljs-string\">\"600x400\"<\/span>)\n\nlabel1 = tk.Label(master=root, text=<span class=\"hljs-string\">\"Place\"<\/span>,bg=<span class=\"hljs-string\">'red'<\/span>,fg=<span class=\"hljs-string\">'white'<\/span>)\nlabel1.place(relx=<span class=\"hljs-number\">0.5<\/span>, rely=<span class=\"hljs-number\">0.5<\/span>, width=<span class=\"hljs-number\">100<\/span>, height=<span class=\"hljs-number\">50<\/span>)\n\nroot.mainloop()\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"602\" height=\"446\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-relative-position.png\" alt=\"tkinter place relative positioning\" class=\"wp-image-6831\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-relative-position.png 602w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-relative-position-300x222.png 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='using-the-anchor-point'>Using the anchor point <a href=\"#using-the-anchor-point\" class=\"anchor\" id=\"using-the-anchor-point\" title=\"Anchor for Using the anchor point\">#<\/a><\/h3>\n\n\n\n<p>The following example places the center point of the Label widget at the center of the window:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\n\nroot = tk.Tk()\nroot.title(<span class=\"hljs-string\">'Tkinter Place Geometry Manager'<\/span>)\nroot.geometry(<span class=\"hljs-string\">\"600x400\"<\/span>)\n\nlabel1 = tk.Label(master=root, text=<span class=\"hljs-string\">\"Place\"<\/span>,bg=<span class=\"hljs-string\">'red'<\/span>,fg=<span class=\"hljs-string\">'white'<\/span>)\nlabel1.place(relx=<span class=\"hljs-number\">0.5<\/span>, rely=<span class=\"hljs-number\">0.5<\/span>, width=<span class=\"hljs-number\">100<\/span>, height=<span class=\"hljs-number\">50<\/span>, anchor=tk.CENTER)\n\nroot.mainloop()\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"444\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-anchor-center.png\" alt=\"tkinter place anchor center\" class=\"wp-image-6833\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-anchor-center.png 600w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2023\/11\/tkinter-place-anchor-center-300x222.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the Tkinter <code>place<\/code> geometry manager to precisely position widgets within its container using the (x, y) coordinate system.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful ?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1313\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-place\/\"\n\t\t\t\tdata-post-title=\"Tkinter Place\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1313\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-place\/\"\n\t\t\t\tdata-post-title=\"Tkinter Place\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\t\t\t<input type=\"button\" name=\"wth-submit\" class=\"wth-btn wth-btn-submit\" id=\"wth-submit\" \/>\n\t\t\t<input type=\"button\" class=\"wth-btn wth-btn-cancel\" value=\"Cancel\" \/>\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, you&#8217;ll learn how to use Tkinter place geometry manager to precisely position widgets within its container using the (x, y) coordinate system.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1232,"menu_order":11,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1313","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/comments?post=1313"}],"version-history":[{"count":1,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1313\/revisions"}],"predecessor-version":[{"id":7390,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1313\/revisions\/7390"}],"up":[{"embeddable":true,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1232"}],"wp:attachment":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/media?parent=1313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}