I am trying to get comfortable with GUI development in python, but I am having a hard time figuring out how to make sure that my cells stay a consistent length. I know that Tkinter will resize the columns to the minimum necessary width, but is it possible to stretch the rest of the cells in that column to fit that width?
The idea of the application itself is very simple. Two labels, with Two Text entries. The functionality of the app will be to edit these two fields in an XML. (not concerned with this part, just the GUI)
NameDropper.py
#!/usr/bin/env python
from Tkinter import *
class NameDropper(Frame):
def __init__(self):
#Create the Mainframe
root = Tk()
root.config(bg="red")
root.title("NameDropper")
mainframe = Frame(root, colormap="new")
mainframe.config(width=200,height=200,bg="green")
# place and configure
mainframe.grid(column=0,row=0,sticky=(N,W,E,S)) #makes Frame appear on screen
#mainframe.columnconfigure(0, weight=1)
#mainframe.rowconfigure(0, weight=1)
self.mainframe = mainframe
self.createVariables()
self.createWidgets()
self.gridWidgets()
self.mainframe.pack(fill=BOTH, expand=YES)
def createVariables(self):
self.start = StringVar()
self.duration = StringVar()
def createWidgets(self):
self.mainframe.startLabel = Label(self.mainframe,text="Start",font=("Helvetica", 16))
self.mainframe.startEntry = Entry(self.mainframe,textvariable=self.start,font=("Helvetica", 16))
self.mainframe.durLabel = Label(self.mainframe,text="Duration",font=("Helvetica", 16))
self.mainframe.durEntry = Entry(self.mainframe,textvariable=self.duration,font=("Helvetica", 16))
self.mainframe.quitButton = Button(self.mainframe,text='Quit',command=self.mainframe.quit)
def gridWidgets(self):
self.mainframe.startLabel.grid(column=0,row=0,sticky=(N,W))
self.mainframe.startLabel.config(bg="red")
self.mainframe.startEntry.grid(column=1,row=0,sticky=(N,W))
self.mainframe.startEntry.config(bg="black")
self.mainframe.durLabel.grid(column=0,row=1,sticky=(N,W))
self.mainframe.durEntry.grid(column=1,row=1,sticky=(N,W))
self.mainframe.quitButton.grid(column=2,row=3,sticky=SE)
if __name__ == '__main__' :
app = NameDropper()
app.mainframe.mainloop()