Why does the 'ipady' option in the tkinter.grid() method only add space below a widget?












1















Below is a code to show the issue. Label1 shows that I need to use pady to displace Label1 by 10 pixels. Label2 shows the default effect of ipady. Why does ipady not leave space above and below the widgets? How do I get ipady to do what it is suppose to do w/o using pady? Thank you.



Quoting tcl documentation:




-ipady amount



The amount specifies how much vertical internal padding to leave on the top and bottom of the slave(s). This space is added
inside the slave(s) border. The amount defaults to 0.




import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

s = ttk.Style()
s.configure('one.TFrame', background='light blue', relief='raised',borderwidth=10)
s.configure('two.TFrame', background='light green', relief='sunken', borderwidth=10)

frame1 = ttk.Frame(root,style='one.TFrame')
frame1.grid(row=0, column=0, sticky='nsew', ipady=10,)

label1 = ttk.Label(frame1, text='Label1')
label1.grid(sticky='nsew',padx=10, pady=10,)

frame2 = ttk.Frame(frame1,style='two.TFrame')
frame2.grid(row=1, column=1, sticky='nsew', ipady=50,)

label2 = ttk.Label(frame2, text='Label2')
label2.grid()









share|improve this question



























    1















    Below is a code to show the issue. Label1 shows that I need to use pady to displace Label1 by 10 pixels. Label2 shows the default effect of ipady. Why does ipady not leave space above and below the widgets? How do I get ipady to do what it is suppose to do w/o using pady? Thank you.



    Quoting tcl documentation:




    -ipady amount



    The amount specifies how much vertical internal padding to leave on the top and bottom of the slave(s). This space is added
    inside the slave(s) border. The amount defaults to 0.




    import tkinter as tk
    import tkinter.ttk as ttk

    root = tk.Tk()

    s = ttk.Style()
    s.configure('one.TFrame', background='light blue', relief='raised',borderwidth=10)
    s.configure('two.TFrame', background='light green', relief='sunken', borderwidth=10)

    frame1 = ttk.Frame(root,style='one.TFrame')
    frame1.grid(row=0, column=0, sticky='nsew', ipady=10,)

    label1 = ttk.Label(frame1, text='Label1')
    label1.grid(sticky='nsew',padx=10, pady=10,)

    frame2 = ttk.Frame(frame1,style='two.TFrame')
    frame2.grid(row=1, column=1, sticky='nsew', ipady=50,)

    label2 = ttk.Label(frame2, text='Label2')
    label2.grid()









    share|improve this question

























      1












      1








      1








      Below is a code to show the issue. Label1 shows that I need to use pady to displace Label1 by 10 pixels. Label2 shows the default effect of ipady. Why does ipady not leave space above and below the widgets? How do I get ipady to do what it is suppose to do w/o using pady? Thank you.



      Quoting tcl documentation:




      -ipady amount



      The amount specifies how much vertical internal padding to leave on the top and bottom of the slave(s). This space is added
      inside the slave(s) border. The amount defaults to 0.




      import tkinter as tk
      import tkinter.ttk as ttk

      root = tk.Tk()

      s = ttk.Style()
      s.configure('one.TFrame', background='light blue', relief='raised',borderwidth=10)
      s.configure('two.TFrame', background='light green', relief='sunken', borderwidth=10)

      frame1 = ttk.Frame(root,style='one.TFrame')
      frame1.grid(row=0, column=0, sticky='nsew', ipady=10,)

      label1 = ttk.Label(frame1, text='Label1')
      label1.grid(sticky='nsew',padx=10, pady=10,)

      frame2 = ttk.Frame(frame1,style='two.TFrame')
      frame2.grid(row=1, column=1, sticky='nsew', ipady=50,)

      label2 = ttk.Label(frame2, text='Label2')
      label2.grid()









      share|improve this question














      Below is a code to show the issue. Label1 shows that I need to use pady to displace Label1 by 10 pixels. Label2 shows the default effect of ipady. Why does ipady not leave space above and below the widgets? How do I get ipady to do what it is suppose to do w/o using pady? Thank you.



      Quoting tcl documentation:




      -ipady amount



      The amount specifies how much vertical internal padding to leave on the top and bottom of the slave(s). This space is added
      inside the slave(s) border. The amount defaults to 0.




      import tkinter as tk
      import tkinter.ttk as ttk

      root = tk.Tk()

      s = ttk.Style()
      s.configure('one.TFrame', background='light blue', relief='raised',borderwidth=10)
      s.configure('two.TFrame', background='light green', relief='sunken', borderwidth=10)

      frame1 = ttk.Frame(root,style='one.TFrame')
      frame1.grid(row=0, column=0, sticky='nsew', ipady=10,)

      label1 = ttk.Label(frame1, text='Label1')
      label1.grid(sticky='nsew',padx=10, pady=10,)

      frame2 = ttk.Frame(frame1,style='two.TFrame')
      frame2.grid(row=1, column=1, sticky='nsew', ipady=50,)

      label2 = ttk.Label(frame2, text='Label2')
      label2.grid()






      python tkinter grid-layout






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 19 at 6:22









      Sun BearSun Bear

      1,647831




      1,647831
























          1 Answer
          1






          active

          oldest

          votes


















          0














          I don't think ipady quite does what you think it does. Admittedly, the documentation is a bit unclear on this point. It doesn't add the equivalent of an interior margin. Instead, it simply adds that many pixels to the height of the widget, and the pixels are added on the inside of the border rather than the outside. It doesn't "block off" these pixels from being used.



          If your frame normally would be 20 pixels tall, with ipady=50, your widget will now be 120 pixels tall (50*2 + 20). Any widgets added inside of this frame are able to use all of the space inside the frame. Thus, when you use grid to place something in row zero, it will still appear at the very top of the frame, just below the border.



          This is exactly what I see with your code. On my machine, frame2 without ipady=50 ends up being 20 pixels tall. When I add ipady=50, the frame becomes 120 pixels tall. The label appears at the very top of the frame since it has been placed in row zero.



          TL;DR: don't think of ipady as saying "I need this much of an inside margin", but rather "I need this much more extra space inside".






          share|improve this answer
























          • Thank you. In this case, the TCL documentation is erroneous and should be corrected to: The amount specifies the number of rows of pixel to extend the widget by. The amount defaults to 0. My suggestion.

            – Sun Bear
            Jan 19 at 12:34













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54264614%2fwhy-does-the-ipady-option-in-the-tkinter-grid-method-only-add-space-below-a%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I don't think ipady quite does what you think it does. Admittedly, the documentation is a bit unclear on this point. It doesn't add the equivalent of an interior margin. Instead, it simply adds that many pixels to the height of the widget, and the pixels are added on the inside of the border rather than the outside. It doesn't "block off" these pixels from being used.



          If your frame normally would be 20 pixels tall, with ipady=50, your widget will now be 120 pixels tall (50*2 + 20). Any widgets added inside of this frame are able to use all of the space inside the frame. Thus, when you use grid to place something in row zero, it will still appear at the very top of the frame, just below the border.



          This is exactly what I see with your code. On my machine, frame2 without ipady=50 ends up being 20 pixels tall. When I add ipady=50, the frame becomes 120 pixels tall. The label appears at the very top of the frame since it has been placed in row zero.



          TL;DR: don't think of ipady as saying "I need this much of an inside margin", but rather "I need this much more extra space inside".






          share|improve this answer
























          • Thank you. In this case, the TCL documentation is erroneous and should be corrected to: The amount specifies the number of rows of pixel to extend the widget by. The amount defaults to 0. My suggestion.

            – Sun Bear
            Jan 19 at 12:34


















          0














          I don't think ipady quite does what you think it does. Admittedly, the documentation is a bit unclear on this point. It doesn't add the equivalent of an interior margin. Instead, it simply adds that many pixels to the height of the widget, and the pixels are added on the inside of the border rather than the outside. It doesn't "block off" these pixels from being used.



          If your frame normally would be 20 pixels tall, with ipady=50, your widget will now be 120 pixels tall (50*2 + 20). Any widgets added inside of this frame are able to use all of the space inside the frame. Thus, when you use grid to place something in row zero, it will still appear at the very top of the frame, just below the border.



          This is exactly what I see with your code. On my machine, frame2 without ipady=50 ends up being 20 pixels tall. When I add ipady=50, the frame becomes 120 pixels tall. The label appears at the very top of the frame since it has been placed in row zero.



          TL;DR: don't think of ipady as saying "I need this much of an inside margin", but rather "I need this much more extra space inside".






          share|improve this answer
























          • Thank you. In this case, the TCL documentation is erroneous and should be corrected to: The amount specifies the number of rows of pixel to extend the widget by. The amount defaults to 0. My suggestion.

            – Sun Bear
            Jan 19 at 12:34
















          0












          0








          0







          I don't think ipady quite does what you think it does. Admittedly, the documentation is a bit unclear on this point. It doesn't add the equivalent of an interior margin. Instead, it simply adds that many pixels to the height of the widget, and the pixels are added on the inside of the border rather than the outside. It doesn't "block off" these pixels from being used.



          If your frame normally would be 20 pixels tall, with ipady=50, your widget will now be 120 pixels tall (50*2 + 20). Any widgets added inside of this frame are able to use all of the space inside the frame. Thus, when you use grid to place something in row zero, it will still appear at the very top of the frame, just below the border.



          This is exactly what I see with your code. On my machine, frame2 without ipady=50 ends up being 20 pixels tall. When I add ipady=50, the frame becomes 120 pixels tall. The label appears at the very top of the frame since it has been placed in row zero.



          TL;DR: don't think of ipady as saying "I need this much of an inside margin", but rather "I need this much more extra space inside".






          share|improve this answer













          I don't think ipady quite does what you think it does. Admittedly, the documentation is a bit unclear on this point. It doesn't add the equivalent of an interior margin. Instead, it simply adds that many pixels to the height of the widget, and the pixels are added on the inside of the border rather than the outside. It doesn't "block off" these pixels from being used.



          If your frame normally would be 20 pixels tall, with ipady=50, your widget will now be 120 pixels tall (50*2 + 20). Any widgets added inside of this frame are able to use all of the space inside the frame. Thus, when you use grid to place something in row zero, it will still appear at the very top of the frame, just below the border.



          This is exactly what I see with your code. On my machine, frame2 without ipady=50 ends up being 20 pixels tall. When I add ipady=50, the frame becomes 120 pixels tall. The label appears at the very top of the frame since it has been placed in row zero.



          TL;DR: don't think of ipady as saying "I need this much of an inside margin", but rather "I need this much more extra space inside".







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 19 at 7:12









          Bryan OakleyBryan Oakley

          216k22258420




          216k22258420













          • Thank you. In this case, the TCL documentation is erroneous and should be corrected to: The amount specifies the number of rows of pixel to extend the widget by. The amount defaults to 0. My suggestion.

            – Sun Bear
            Jan 19 at 12:34





















          • Thank you. In this case, the TCL documentation is erroneous and should be corrected to: The amount specifies the number of rows of pixel to extend the widget by. The amount defaults to 0. My suggestion.

            – Sun Bear
            Jan 19 at 12:34



















          Thank you. In this case, the TCL documentation is erroneous and should be corrected to: The amount specifies the number of rows of pixel to extend the widget by. The amount defaults to 0. My suggestion.

          – Sun Bear
          Jan 19 at 12:34







          Thank you. In this case, the TCL documentation is erroneous and should be corrected to: The amount specifies the number of rows of pixel to extend the widget by. The amount defaults to 0. My suggestion.

          – Sun Bear
          Jan 19 at 12:34




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54264614%2fwhy-does-the-ipady-option-in-the-tkinter-grid-method-only-add-space-below-a%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Homophylophilia

          Updating UILabel text programmatically using a function

          Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage