{"id":1268,"date":"2020-11-26T02:23:46","date_gmt":"2020-11-26T02:23:46","guid":{"rendered":"https:\/\/www.pythontutorial.net\/?page_id=1268"},"modified":"2025-04-02T13:34:28","modified_gmt":"2025-04-02T13:34:28","slug":"tkinter-separator","status":"publish","type":"page","link":"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-separator\/","title":{"rendered":"Tkinter Separator"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn how to use the Tkinter Separator widget to display a thin horizontal or vertical rule between groups of widgets.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='introduction-to-the-tkinter-separator-widget'>Introduction to the Tkinter Separator widget <a href=\"#introduction-to-the-tkinter-separator-widget\" class=\"anchor\" id=\"introduction-to-the-tkinter-separator-widget\" title=\"Anchor for Introduction to the Tkinter Separator widget\">#<\/a><\/h2>\n\n\n\n<p>A Separator widget places a thin horizontal or vertical rule between two groups of <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-ttk\/\">widgets<\/a>.<\/p>\n\n\n\n<p>To create a separator widget, you follow these steps:<\/p>\n\n\n\n<p>First, import <code>tkinter<\/code> as <code>ttk<\/code>:<\/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\"><span class=\"hljs-keyword\">from<\/span> tkinter <span class=\"hljs-keyword\">import<\/span> ttk<\/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>Second, create a separator using the <code>Separator<\/code> constructor:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\">sep = ttk.Separator(master=<span class=\"hljs-literal\">None<\/span>, orient=tk.HORIZONTAL)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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>The <code>Separator<\/code> constructor accepts two main parameters:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>master<\/code> is the container widget where you want to place the <code>Separator<\/code> .<\/li>\n\n\n\n<li><code>orient<\/code> determines the orientation of the separator. It can can be either <code>tk.VERTICAL<\/code> or <code>tk.HORIZONTAL<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id='horizontal-separator'>Horizontal separator <a href=\"#horizontal-separator\" class=\"anchor\" id=\"horizontal-separator\" title=\"Anchor for Horizontal separator\">#<\/a><\/h2>\n\n\n\n<p>The following program illustrates how to use a Separator widget to separate two frames:<\/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.geometry(<span class=\"hljs-string\">'300x200'<\/span>)\nroot.title(<span class=\"hljs-string\">'Separator Widget Demo'<\/span>)\n\n<span class=\"hljs-comment\"># top frame<\/span>\ntop_frame = tk.Frame(root)\ntop_frame.pack(side=tk.TOP, fill=tk.BOTH, expand=<span class=\"hljs-literal\">True<\/span>)\nttk.Label(top_frame, text=<span class=\"hljs-string\">\"Top frame\"<\/span>).pack(pady=<span class=\"hljs-number\">20<\/span>)\n\n<span class=\"hljs-comment\"># create a horizontal separator<\/span>\nseparator = ttk.Separator(root, orient=tk.HORIZONTAL)\nseparator.pack(side=tk.TOP, fill=tk.X, pady=<span class=\"hljs-number\">5<\/span>)\n\n<span class=\"hljs-comment\"># bottom frame<\/span>\nbottom_frame = tk.Frame(root)\nbottom_frame.pack(side=tk.BOTTOM, fill=tk.BOTH, expand=<span class=\"hljs-literal\">True<\/span>)\nttk.Label(bottom_frame, text=<span class=\"hljs-string\">\"Bottom frame\"<\/span>).pack(pady=<span class=\"hljs-number\">20<\/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\">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-full\"><img loading=\"lazy\" decoding=\"async\" width=\"302\" height=\"232\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-horizontal-separator.png\" alt=\"tkinter horizontal separator\" class=\"wp-image-7382\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-horizontal-separator.png 302w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-horizontal-separator-300x230.png 300w\" sizes=\"auto, (max-width: 302px) 100vw, 302px\" \/><\/figure>\n\n\n\n<p>How it works:<\/p>\n\n\n\n<p>First, create a horizontal Separator widget by passing the <code>tk.HORIZONTAL<\/code> to the <code>Separator<\/code> constructor:<\/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\">separator = ttk.Separator(root, orient=tk.HORIZONTAL)<\/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, <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-pack\/\" target=\"_blank\" rel=\"noreferrer noopener\">pack<\/a> the Separator on the main window:<\/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\">separator.pack(side=tk.TOP, fill=tk.X, pady=<span class=\"hljs-number\">5<\/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>We set the <code><a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-pack\/#fill\">fill<\/a><\/code> to <code>tk.X<\/code> to expand the separator horizontally. If you don&#8217;t do this, you won&#8217;t see the Separator widget.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='vertical-separator'>Vertical Separator <a href=\"#vertical-separator\" class=\"anchor\" id=\"vertical-separator\" title=\"Anchor for Vertical Separator\">#<\/a><\/h2>\n\n\n\n<p>The following program shows how to create a veritcal Separator widget:<\/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\"><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.geometry(<span class=\"hljs-string\">'300x200'<\/span>)\nroot.title(<span class=\"hljs-string\">'Separator Widget Demo'<\/span>)\n\n<span class=\"hljs-comment\"># left frame<\/span>\nleft_frame = tk.Frame(root)\nleft_frame.pack(side=tk.LEFT, fill=tk.BOTH, expand=<span class=\"hljs-literal\">True<\/span>)\nttk.Label(left_frame, text=<span class=\"hljs-string\">\"Left frame\"<\/span>).pack(pady=<span class=\"hljs-number\">20<\/span>)\n\n<span class=\"hljs-comment\"># right frame<\/span>\nright_frame = tk.Frame(root)\nright_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=<span class=\"hljs-literal\">True<\/span>)\nttk.Label(right_frame, text=<span class=\"hljs-string\">\"Right frame\"<\/span>).pack(pady=<span class=\"hljs-number\">20<\/span>)\n\n<span class=\"hljs-comment\"># create a vertical separator<\/span>\nseparator = ttk.Separator(root, orient=tk.HORIZONTAL)\nseparator.pack(side=tk.LEFT, fill=tk.Y, padx=<span class=\"hljs-number\">5<\/span>)\n\n\nroot.mainloop()<\/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<p>Output:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"302\" height=\"232\" src=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-vertical-separator.png\" alt=\"tkinter vertical separator\" class=\"wp-image-7381\" srcset=\"https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-vertical-separator.png 302w, https:\/\/www.pythontutorial.net\/wp-content\/uploads\/2025\/04\/tkinter-vertical-separator-300x230.png 300w\" sizes=\"auto, (max-width: 302px) 100vw, 302px\" \/><\/figure>\n\n\n\n<p>How it works:<\/p>\n\n\n\n<p>First, create a vertical Separator widget by passing the <code>tk.HORIZONTAL<\/code>to the <code>Separator<\/code> constructor:<\/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\">separator = ttk.Separator(root, orient=tk.HORIZONTAL)<\/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>Second, <a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-pack\/\" target=\"_blank\" rel=\"noreferrer noopener\">pack<\/a> the Separator on the main window:<\/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\">separator.pack(side=tk.LEFT, fill=tk.Y, padx=<span class=\"hljs-number\">5<\/span>)<\/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><a href=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-pack\/#fill\">fill<\/a><\/code> to <code>tk.X<\/code> to expand the separator horizontally.<\/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 a separator widget to place a thin horizontal or vertical rule between two groups of widgets.<\/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=\"1268\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-separator\/\"\n\t\t\t\tdata-post-title=\"Tkinter Separator\"\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=\"1268\"\n\t\t\t\tdata-post-url=\"https:\/\/www.pythontutorial.net\/tkinter\/tkinter-separator\/\"\n\t\t\t\tdata-post-title=\"Tkinter Separator\"\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 Separator widget to display a thin horizontal or vertical rule between groups of widgets.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1232,"menu_order":17,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1268","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1268","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=1268"}],"version-history":[{"count":4,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1268\/revisions"}],"predecessor-version":[{"id":7387,"href":"https:\/\/www.pythontutorial.net\/wp-json\/wp\/v2\/pages\/1268\/revisions\/7387"}],"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=1268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}