tkinter: loading file before entering mainloop

Peter Billam peter at www.pjb.com.au
Sat Mar 14 01:06:11 EDT 2009


Greetings,

I've got this tkinter program which allows you to load a file with
File/LoadFile or Ctrl-L or from the Alt-F menu, as usual. But I'd
also like to be able to invoke it with:
  shellprompt> midimix x.mid
and have it invoke its usual loadFile method on x.mid
But with the top-level code:

  application = tkinter.Tk()
  window = MainWindow(application)
  if (len(sys.argv) > 1) and os.path.exists(sys.argv[1]):
      window.loadFile(sys.argv[1])
  application.mainloop()

it crashes:
  File "./midimix", line 465, in loadFile
    space0.grid(row=grid_row,
     pady=round(0.5*(ymid[track_num]-ymid[track_num-1]))-50)
  File "/usr/local/lib/python3.0/tkinter/__init__.py",
   line 1845, in grid_configure
    + self._options(cnf, kw))
  _tkinter.TclError: bad pad value "-50": must be positive screen distance

presumably because the window doesn't have dimensions before mainloop
is entered.  Can I force the window to be laid out before entering
mainloop? Or can I invoke loadFile() after mainloop has started ?
Help gratefully received...

Regards,  Peter

-- 
Peter Billam       www.pjb.com.au    www.pjb.com.au/comp/contact.html



More information about the Python-list mailing list