Screen resolution again

jepler at unpythonic.net jepler at unpythonic.net
Sun Jun 9 23:11:48 EDT 2002


On Windows only (according to the manpage, anyway), you can also use
'wm_state' to maximize your window:
    from Tkinter import *
    root = Tk()
    canvas = Canvas(root)
    root.wm_state("zoomed")
It's unfortuante that this is not supported under Unix.

With modern Unix window managers, you can send a _WIN_STATE message to set
WIN_STATE_MAXIMIZED_VIRT |WIN_STATE_MAXIMIZED_HORIZ .. I don't know how
to do this in pure Tk(inter), though.  If you're into this kind of thing,
here's some C code that is down the right alley...

int maximize( Tk_Window tkw, int flag ) 
{ 
        Window w, root; 
    XClientMessageEvent xev; 
    Status res; 
    static Atom _WIN_STATE = 0; 
 
     
    if( !tkw ) { 
        return TCL_ERROR; 
    } 
     
    if( !_WIN_LAYER ) 
        _WIN_STATE = XInternAtom ( Tk_Display( tkw ), "_WIN_STATE", False); 
     
    root = RootWindow( Tk_Display( tkw ), Tk_ScreenNumber( tkw ) );     
    tkw = TkpGetWrapperWindow( tkw ); 
    w = Tk_WindowId( tkw );     
    xev.type = ClientMessage; 
    xev.window = w; 
    xev.message_type = _WIN_STATE; 
     
    xev.format = 32; 
    xev.data.l[0] = WIN_STATE_MAXIMIZED_VERT | WIN_STATE_MAXIMIZED_HORIZ; 
    if( flag ) 
        xev.data.l[1] = WIN_STATE_MAXIMIZED_VERT | WIN_STATE_MAXIMIZED_HORIZ; 
    else 
        xev.data.l[1] = 0;     
     
    res = XSendEvent ( Tk_Display( tkw ), root, False, SubstructureNotifyMask, 
     
    if( !res ) 
    {    
        Tcl_AppendResult("XSendEvent failed");
	return TCL_ERROR;
    } 
     
    XFlush (display); 
 
    return TCL_OK; 
}





More information about the Python-list mailing list