0

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()

Image of GUI

NameDropper.img

mlwn
  • 1,156
  • 1
  • 10
  • 25
Busturdust
  • 2,447
  • 24
  • 41
  • 1
    If you are just getting started then I would suggest that you don't. wxPython is far advanced and easier to use - especially the packing (sizers) part. – Renae Lider Jul 23 '15 at 19:47
  • Thanks, I will check that out before continuing – Busturdust Jul 23 '15 at 19:47
  • 1
    @RenaeLider: I think that's very bad advice. Tkinter is a perfect toolkit to learn with. It is more powerful than wxPython in some ways, less powerful in others. For most people, for most projects, it has more than enough functionality. As for the "packing (sizers)", your experience seems different from mine. I find tkinter's three geometry managers to be far, far, _far_ superior to wxPython's sizers. In fact, I'd go so far to say as Tkitner's three geometry managers are better than any other toolkit in any language, both in power and ease of use. – Bryan Oakley Jul 23 '15 at 19:48
  • @BryanOakley I've been using both for quite a while now, but never have I noticed a superior aspect in Tkinter other than the fact that it is builtin in to the distribution. *wxPython is the best and most mature cross-platform GUI toolkit, given a number of constraints. The only reason wxPython isn't the standard Python GUI toolkit is that Tkinter was there first.* -- Guido van Rossum – Renae Lider Jul 23 '15 at 19:52
  • @RenaeLider: with all due respect to Guido, he's not a GUI programmer. While his opinion carries some weight, I hardly consider it authoritative on this specific matter. Personally I find the text widget and the canvas in Tkinter to be superior to what wxPython has, for most uses. I spent a year and a half or so full time with wxPython, and finally went back to tkinter out of sheer frustration. In my experience, wxPython was harder to use and less stable. Clearly your experience is different. I just want to make sure someone new to GUI programming can see more than one viewpoint. – Bryan Oakley Jul 23 '15 at 19:54
  • @BryanOakley Thanks for the link, Dont know how I missd that. And also thanks for the input on wx vs tk also, I will investigate both over time as they both seem to have their perks and nuances. Thanks again guys – Busturdust Jul 23 '15 at 20:35

0 Answers0