Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are 3 geometry managers that you have available to you -- <code>grid</code>, <code>pack</code> and <code>place</code>. The third is the most general, but also very difficult to use. I prefer <code>grid</code>. Note that you can place widgets inside of other widgets -- Or you can specify <code>columnspan</code>. So, if you want to get the following layout:</p> <pre><code> ------------------------- | Button1 | Button2 | ------------------------- | Big Widget | ------------------------- </code></pre> <p>there are 2 canonical ways to do it using <code>.grid</code>. The first method is <code>columnspan</code>:</p> <pre><code>import Tkinter as Tk root = Tk.Tk() b1 = Tk.Button(root,text="Button1") b1.grid(row=0,column=0) b2 = Tk.Button(root,text="Button2") b2.grid(row=0,column=1) big_widget = Tk.Canvas(root) big_widget.grid(row=1,column=0,columnspan=2) </code></pre> <p>*note that there is a completely analogous <code>rowspan</code> option as well.</p> <p>The second method is to use a <code>Frame</code> to hold your buttons:</p> <pre><code>import Tkinter as Tk root = Tk.Tk() f = Tk.Frame(root) f.grid(row=0,column=0) #place buttons on the *frame* b1 = Tk.Button(f,text="Button1") b1.grid(row=0,column=0) b2 = Tk.Button(f,text="Button2") b2.grid(row=0,column=1) big_widget = Tk.Canvas(root) big_widget.grid(row=1,column=0) #don't need columnspan any more. </code></pre> <p>This method is <strong>SUPER</strong> useful for creating complex layouts -- I don't know how you could create a complex layout without using <code>Frame</code> objects like this ...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload