Screen resolution again

Martin Franklin mfranklin1 at gatwick.westerngeco.slb.com
Sun Jun 9 22:44:42 CEST 2002


On Sunday 09 Jun 2002 5:59 pm, you wrote:
> I am still trying to figure out how to automatically create a canvas
> that is sized according to the screen resolution using tkinter on a
> win95 box and python 2.2.1.  The hack below sort of does that, but I
> would appreciate advice, suggestions or pointers to a url on how to do
> it correctly.  Note that I create an extra canvas get the root height
> and windth.
>
> david lees
> -------------------
>
> from Tkinter import *
> root = Tk()
>
> root.title('Drawing')
> canvas = Canvas(root,width=20,height=20,bg='white')
> canvas.pack()
>
> h = canvas.winfo_vrootheight()
> w = canvas.winfo_vrootwidth()
>
>
> print w,h
> canvas2 = Canvas(root,width=w-30,height=h-30,bg='white')
> canvas2.pack()
>
> root.mainloop()

Why not call winfo_vrootheight() on root, that at least gets rid of the first 
canvas.  I used this to test and it seemed to work but did not fill the 
entire screen I guess there is a bit of slack for the window decorations etc.
however i'm running RedHat linux 7.2 with KDE What happens when you run this 
exactly?

import Tkinter
root=Tkinter.Tk()
root_height=root.winfo_vrootheight()
root_width=root.winfo_vrootwidth()

print root_height, root_width # on my screen this prints 768 1024

canvas=Tkinter.Canvas(root, width=root_width, height=root_height)
canvas.pack()
root.mainloop()












More information about the Python-list mailing list