{"id":1804,"date":"2020-12-25T04:18:37","date_gmt":"2020-12-25T04:18:37","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=1804"},"modified":"2021-01-05T06:43:20","modified_gmt":"2021-01-05T06:43:20","slug":"tkinter-panedwindow","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-panedwindow\/","title":{"rendered":"Tkinter PanedWindow"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the Tkinter PanedWindow widget to divide the space of a frame or a window.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-tkinter-panedwindow-widget'>Introduction to the Tkinter PanedWindow widget <a href=\"#introduction-to-the-tkinter-panedwindow-widget\" class=\"anchor\" id=\"introduction-to-the-tkinter-panedwindow-widget\" title=\"Anchor for Introduction to the Tkinter PanedWindow widget\">#<\/a><\/h2>\n\n\n\n<p>The <code>PaneWindow<\/code> widget divides the space of a <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-frame\/\">frame<\/a> or a <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-window\/\">window<\/a>. A <code>PaneWindow<\/code> is like a <code>Frame<\/code> that acts as a container for holding child widgets<\/p>\n\n\n\n<p>Typically, a <code>PanedWindow<\/code> contains a vertical or horizontal stack of child widgets:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"355\" height=\"284\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/Tkinter-PanedWindow-Demo.gif\" alt=\"\" class=\"wp-image-1807\"\/><\/figure><\/div>\n\n\n\n<p>A <code>PanedWindow<\/code> uses a bar to separate the child widgets. This bar is called a <em>sash<\/em>.<\/p>\n\n\n\n<p>A <em>sash<\/em> can have a <em>handle<\/em> which is a small square that you can drag it with a mouse:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"302\" height=\"232\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/Tkinter-PanedWindow-Components.png\" alt=\"\" class=\"wp-image-1805\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/Tkinter-PanedWindow-Components.png 302w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/Tkinter-PanedWindow-Components-300x230.png 300w\" sizes=\"auto, (max-width: 302px) 100vw, 302px\" \/><\/figure><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>A <em>pane<\/em> is an area occupied by one child widget.<\/p>\n\n\n\n<p>To create a <code>PanedWindow<\/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=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">ttk<\/span><span class=\"hljs-selector-class\">.PanedWindow<\/span>(<span class=\"hljs-selector-tag\">container<\/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<p>A notable option of a <code>PanedWindow<\/code> widget is the <code>orient<\/code> option.<\/p>\n\n\n\n<p>If you set the <code>orient<\/code> to <code>tk.HORIZONTAL<\/code>, it&#8217;ll stack child widgets side by side. If <code>orient<\/code> is <code>tk.VERTICAL<\/code>, it&#8217;ll stack child widgets top to bottom. The <code>orient<\/code> option defaults to <code>tk.VERTICAL<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='tkinter-panedwindow-widget-example'>Tkinter PanedWindow widget example <a href=\"#tkinter-panedwindow-widget-example\" class=\"anchor\" id=\"tkinter-panedwindow-widget-example\" title=\"Anchor for Tkinter PanedWindow widget example\">#<\/a><\/h2>\n\n\n\n<p>The following example illustrates how to use the <code>PanedWindow<\/code> widget to separate two <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-listbox\/\">Listbox<\/a> widgets:<\/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\">import tkinter <span class=\"hljs-keyword\">as<\/span> tk\nfrom tkinter import ttk\n\nroot = tk.Tk()\nroot.title(<span class=\"hljs-string\">'PanedWindow Demo'<\/span>)\nroot.geometry(<span class=\"hljs-string\">'300x200'<\/span>)\n\n<span class=\"hljs-comment\"># change style to classic (Windows only) <\/span>\n<span class=\"hljs-comment\"># to show the sash and handle<\/span>\nstyle = ttk.Style()\nstyle.theme_use(<span class=\"hljs-string\">'classic'<\/span>)\n\n<span class=\"hljs-comment\"># paned window<\/span>\npw = ttk.PanedWindow(orient=tk.HORIZONTAL)\n\n<span class=\"hljs-comment\"># Left listbox<\/span>\nleft_list = tk.Listbox(root)\nleft_list.pack(side=tk.LEFT)\npw.add(left_list)\n\n<span class=\"hljs-comment\"># Right listbox<\/span>\nright_list = tk.Listbox(root)\nright_list.pack(side=tk.LEFT)\npw.add(right_list)\n\n<span class=\"hljs-comment\"># place the panedwindow on the root window<\/span>\npw.pack(fill=tk.BOTH, expand=<span class=\"hljs-keyword\">True<\/span>)\n\nroot.mainloop()<\/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<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"302\" height=\"232\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/Tkinter-PanedWindow.png\" alt=\"\" class=\"wp-image-1806\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/Tkinter-PanedWindow.png 302w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2020\/12\/Tkinter-PanedWindow-300x230.png 300w\" sizes=\"auto, (max-width: 302px) 100vw, 302px\" \/><\/figure>\n\n\n\n<p>If you run the program on Windows, you&#8217;re likely will not see the sash and handle displaying. To make it visible, you can set the default theme to <code>classic<\/code><\/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\"><li>Use the Tkinter <code>PanedWindow<\/code> widget to divide the space of a window or a frame.<\/li><\/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=\"1804\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-panedwindow\/\"\n\t\t\t\tdata-post-title=\"Tkinter PanedWindow\"\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=\"1804\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-panedwindow\/\"\n\t\t\t\tdata-post-title=\"Tkinter PanedWindow\"\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 PanedWindow widget to divide the space of a frame or a window.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1232,"menu_order":21,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1804","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1804","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=1804"}],"version-history":[{"count":0,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1804\/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=1804"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}