My Complaint
I am currently delving deeper than “ever” before into the Tkinter GUI, and I have found the .grid() geometry manager to be inadequate for several reasons:
-
The plots are based on the largest widget within them – this relativity leads to inaccuracy.
-
In Windows 7, on Python 2.7.3, the program does not seem to heed my row numbers, instead preferring to use the order of the widgets.
My Code
I am currently working on a really basic text editor, and I want to have multiple buttons on the top of the frame. I have been unable to do this as my widgets are placed either to the far left or right of the massive textbox that dominates the center of the screen.
========Class __init__ Stuff============
def widget(self):#Place widgets here
#Save Button
self.saveButton = Button (self, text = "Save", command = self.saveMe)
self.saveButton.grid(column = 0, row = 0, sticky = W)
#Open Button
self.openButton = Button (self, text = "Open", command = self.openMe)
self.openButton.grid(column = 0, row = 1, sticky = W)
#Area where you write
self.text = Text (self, width = (root.winfo_screenwidth() - 20),
height = (root.winfo_screenheight() - 10))
self.text.grid(row = 2)
==============Mainloop/Command Stuff============
My Question
Is there another way to use the .grid() geometry manager in a way that is more accurate, or should I be using another function altogether?
Thanks!
There are 3 geometry managers that you have available to you —
grid,packandplace. The third is the most general, but also very difficult to use. I prefergrid. Note that you can place widgets inside of other widgets — Or you can specifycolumnspan. So, if you want to get the following layout:there are 2 canonical ways to do it using
.grid. The first method iscolumnspan:*note that there is a completely analogous
rowspanoption as well.The second method is to use a
Frameto hold your buttons:This method is SUPER useful for creating complex layouts — I don’t know how you could create a complex layout without using
Frameobjects like this …