tkinter: loading file before entering mainloop
Peter Billam
peter at www.pjb.com.au
Mon Mar 16 03:45:55 EDT 2009
Peter Billam wrote:
>> They're multiplied up from
>> canvas_height = self.canvas.winfo_height()
>> so I guess mainloop already think it's idle, while grid is still
>> taking 10ms to work out what goes where.
On 2009-03-15, John McMonagle <jmcmonagle at NO.SPAM.velseis.com.au> wrote:
> You need to query the requested width and height for windows which
> are not yet realised.
> canvas_height = self.canvas.winfo_reqheight()
Good suggestion: it didn't work for me, perhaps because I just ask for
an overall window geometry, then leave it to grid to assign as much
as possible to the canvas? This does the job:
num_retries = 0
...
canvas_height = self.canvas.winfo_height()
global num_retries
if canvas_height < 5: # is 1 in the 10ms it takes for grid to work
if num_retries > 4:
print("loadFile: can't get canvas height",file=sys.stderr)
num_retries = 0
return
application.after(50, self.loadFile, sys.argv[1])
num_retries += 1
return
though I'm not quite sure how :-) because
application = tkinter.Tk()
at the top level, and I haven't had to declare
global application
within loadFile...
I am a python newbie, so things mysterious to me do happen.
Regards, Peter
--
Peter Billam www.pjb.com.au www.pjb.com.au/comp/contact.html
More information about the Python-list
mailing list