{"id":1797,"date":"2020-12-25T01:45:41","date_gmt":"2020-12-25T01:45:41","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=1797"},"modified":"2023-11-16T00:58:20","modified_gmt":"2023-11-16T00:58:20","slug":"tkinter-sizegrip","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-sizegrip\/","title":{"rendered":"Tkinter Sizegrip"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the Tkinter <code>Sizegrip<\/code> widget that allows you to resize the entire application window.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-tkinter-sizegrip-widget'>Introduction to the Tkinter Sizegrip widget <a href=\"#introduction-to-the-tkinter-sizegrip-widget\" class=\"anchor\" id=\"introduction-to-the-tkinter-sizegrip-widget\" title=\"Anchor for Introduction to the Tkinter Sizegrip widget\">#<\/a><\/h2>\n\n\n\n<p>The <code>Sizegrip<\/code> widget is typically located in the bottom-right corner of the window. It allows you to resize the entire application window:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"431\" height=\"330\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/Tkinter-Sizegrip-Demo.gif\" alt=\"\" class=\"wp-image-1800\"\/><\/figure>\n\n\n\n<p>To create a <code>Sizegrip<\/code> widget, you use the following syntax:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">ttk.Sizegrip(master, **kw)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this syntax:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>master<\/code>: specify the parent widget where you want to place the Sizegrip. Typically, it is the main window.<\/li>\n\n\n\n<li><code>**kw<\/code>: specify the keyword arguments that configure the size grip&#8217;s appearance and behavior.<\/li>\n<\/ul>\n\n\n\n<p>To make sure the <code>Sizegrip<\/code> widget works properly, you need to make the parent widget resizable. <\/p>\n\n\n\n<p>If you use the main window e.g., <code>root<\/code>, you need to call the <code>resizable()<\/code> method with <code>True<\/code> values:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">root.resizable(<span class=\"hljs-keyword\">True<\/span>, <span class=\"hljs-keyword\">True<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='tkinter-sizegrip-widget-examples'>Tkinter Sizegrip widget examples <a href=\"#tkinter-sizegrip-widget-examples\" class=\"anchor\" id=\"tkinter-sizegrip-widget-examples\" title=\"Anchor for Tkinter Sizegrip widget examples\">#<\/a><\/h2>\n\n\n\n<p>Let&#8217;s take some examples of using the Sizegrip widget.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='1-using-the-sizegrip-widget-with-a-grid-layout'>1) Using the Sizegrip widget with a grid layout <a href=\"#1-using-the-sizegrip-widget-with-a-grid-layout\" class=\"anchor\" id=\"1-using-the-sizegrip-widget-with-a-grid-layout\" title=\"Anchor for 1) Using the Sizegrip widget with a grid layout\">#<\/a><\/h3>\n\n\n\n<p>The following program creates and shows <code>Sizegrip<\/code> at the bottom-right corner of the main window using the <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-grid\/\">grid layout<\/a>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\n<span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk\n\nroot = tk.Tk()\nroot.title(<span class=\"hljs-string\">'Sizegrip Demo'<\/span>)\nroot.geometry(<span class=\"hljs-string\">'300x200'<\/span>)\nroot.resizable(<span class=\"hljs-literal\">True<\/span>, <span class=\"hljs-literal\">True<\/span>)\n\n<span class=\"hljs-comment\"># grid layout<\/span>\nroot.columnconfigure(<span class=\"hljs-number\">0<\/span>, weight=<span class=\"hljs-number\">1<\/span>)\nroot.rowconfigure(<span class=\"hljs-number\">0<\/span>, weight=<span class=\"hljs-number\">1<\/span>)\n\n<span class=\"hljs-comment\"># create the sizegrip<\/span>\nsizegrip = ttk.Sizegrip(root)\nsizegrip.grid(row=<span class=\"hljs-number\">1<\/span>, sticky=tk.SE)\n\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\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/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-large\"><img loading=\"lazy\" decoding=\"async\" width=\"333\" height=\"239\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/tkinter-sizegrip.png\" alt=\"Tkinter Sizegrip Widget Demo\" class=\"wp-image-1798\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/tkinter-sizegrip.png 333w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/tkinter-sizegrip-300x215.png 300w\" sizes=\"auto, (max-width: 333px) 100vw, 333px\" \/><\/figure>\n\n\n\n<p><br>How it works.<\/p>\n\n\n\n<p>First, make sure the root window is resizable:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">root.resizable(<span class=\"hljs-literal\">True<\/span>, <span class=\"hljs-literal\">True<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, configure the grid layout:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">root.columnconfigure(<span class=\"hljs-number\">0<\/span>, weight=<span class=\"hljs-number\">1<\/span>)\nroot.rowconfigure(<span class=\"hljs-number\">0<\/span>, weight=<span class=\"hljs-number\">1<\/span>)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, create a <code>Sizegrip<\/code> widget and place at the bottom-right corner of the window:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">sg = ttk.Sizegrip(root)\nsg.grid(row=<span class=\"hljs-number\">1<\/span>, sticky=tk.SE)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\" id='2-using-the-sizegrip-widget-with-the-place-layout'>2) Using the Sizegrip widget with the place layout <a href=\"#2-using-the-sizegrip-widget-with-the-place-layout\" class=\"anchor\" id=\"2-using-the-sizegrip-widget-with-the-place-layout\" title=\"Anchor for 2) Using the Sizegrip widget with the place layout\">#<\/a><\/h3>\n\n\n\n<p>The following program demonstrates how to create a <code>Sizegrip<\/code> widget and place it at the bottom-right corner of the window using the <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-place\/\">place()<\/a> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\r\n<span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk\r\n\r\nroot = tk.Tk()\r\nroot.resizable(<span class=\"hljs-literal\">True<\/span>, <span class=\"hljs-literal\">True<\/span>)\r\n\r\n<span class=\"hljs-comment\"># create a sizegrip and place it at <\/span>\r\n<span class=\"hljs-comment\"># the bottom-right corner of the window<\/span>\r\nsizegrip = ttk.Sizegrip(root)\r\nsizegrip.place(relx=<span class=\"hljs-number\">1<\/span>, rely=<span class=\"hljs-number\">1<\/span>, anchor=tk.SE)\r\n\r\nroot.mainloop()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, we set the <code>relx<\/code> and <code>rely<\/code> parameters of the <code>place()<\/code> method to 1.0 to place the Sizegrip widget at the bottom-right corner of the main window. We also set the <code>anchor<\/code> parameter to <code>tk.SE<\/code> to place the south-east point of the Sizegrip to the specified coordinates.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='3-using-the-sizegrip-widget-with-the-pack-layout'>3) Using the Sizegrip widget with the pack layout <a href=\"#3-using-the-sizegrip-widget-with-the-pack-layout\" class=\"anchor\" id=\"3-using-the-sizegrip-widget-with-the-pack-layout\" title=\"Anchor for 3) Using the Sizegrip widget with the pack layout\">#<\/a><\/h3>\n\n\n\n<p>The following program creates a Sizegrip widget and places it at the bottom-right corner using the <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-pack\/\">pack()<\/a> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">import<\/span> tkinter <span class=\"hljs-keyword\">as<\/span> tk\r\n<span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk\r\n\r\nroot = tk.Tk()\r\nroot.geometry(<span class=\"hljs-string\">'300x200'<\/span>)\r\nroot.resizable(<span class=\"hljs-literal\">True<\/span>, <span class=\"hljs-literal\">True<\/span>)\r\n\r\n\r\n<span class=\"hljs-comment\"># Pack the Sizegrip at the <\/span>\r\n<span class=\"hljs-comment\"># bottom-right corner of the window<\/span>\r\nsizegrip = ttk.Sizegrip(root)\r\nsizegrip.pack(side=<span class=\"hljs-string\">\"bottom\"<\/span>, anchor=tk.SE)\r\n\r\nroot.mainloop()\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>In this example, we set the <code>side<\/code> parameter to &#8220;bottom,&#8221; and the <code>anchor<\/code> parameter to &#8220;se&#8221; to position the <code>Sizegrip<\/code> at the bottom-right corner of the window.<\/p>\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>Sizegrip<\/code> widget to allow users to resize the entire window application.<\/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=\"1797\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-sizegrip\/\"\n\t\t\t\tdata-post-title=\"Tkinter Sizegrip\"\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=\"1797\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-sizegrip\/\"\n\t\t\t\tdata-post-title=\"Tkinter Sizegrip\"\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 the Tkinter Sizegrip widget that allows you to resize the entire application window.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1232,"menu_order":24,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1797","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1797","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=1797"}],"version-history":[{"count":0,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1797\/revisions"}],"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=1797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}