I am teaching myself Python and attempting to build a local app that uses a window GUI. I am having a lot of trouble trying to layout the screen with grid()
. I have searched and tried lots of different snippets of code, but I have the same problem, the frames and widgets don't seem to be formatting. The code below is really simplistic, but my end goal is to master how to use grid()
so I can build any GUI I like in the future.
I want to be able to do the following:
--Window-----------------
| Section 1 | Section 2 |
| | |
-------------------------
| Section 3 |
| |
| |
-------------------------
from Tkinter import Button, Frame, Entry, Tk, Label, Menubutton, Menu, IntVar
class MainScreen(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.searchSection()
self.quitButton()
def searchSection(self):
# Create Search Section
self.searchFrame = Frame(self.master, bg='grey', relief='sunken', width=200, height=200)
self.searchFrame.grid(row=0, column=0, rowspan=5, columnspan=30, sticky="wens")
Label(self.searchFrame, text="Search :", bg='grey').grid(row=1, column=1, columnspan=20, sticky='w')
self.searchField = Entry(self.searchFrame)
self.searchField.grid(row=2, column=1, columnspan=7, sticky='w')
#Create Menu Options
self.search = Menubutton(self.searchFrame, text = "Search", bg='grey')
self.search.grid(row=2, column=8, columnspan=3, sticky='w')
self.search.menu = Menu(self.search, tearoff = 0)
self.search['menu'] = self.search.menu
self.SearchType1Var = IntVar()
self.search.menu.add_checkbutton(label="SearchType1", variable = self.SearchType1Var)
def quitButton(self):
## Provide a quit button to exit the rogram
self.quitFrame = Frame(self.master, bg='grey', width=50, height=50)
self.quitFrame.grid(row=0, column=20, rowspan=5, columnspan=5, sticky='ewns')
self.quitButton = Button(self.quitFrame, text="Quit", command=exit)
self.quitButton.grid()
if __name__ == '__main__':
root = Tk()
root.title("Learn Grid GUI")
root.geometry("800x600+200+150")
main = MainScreen(root)
root.mainloop()