[GRASS-dev] Using current grass gui.tcl in python programs.

Michael Barton michael.barton at asu.edu
Sat Jul 15 20:39:25 EDT 2006


Thanks Cedric.

Good to see you back.

Doesn't Tkinter require TclTk to be installed? If so, is there an advantage
to having gui.tcl run under Python/Tkinter vs. Wish as it does now? That is,
the wxPython prototype I'm working on can launch a GRASS command and it's
TclTk gui. Of course this means I'm running part of the UI under TclTk and
part under wxPython at the moment. Does Tkinter change this?

Michael
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton



> From: Cedric Shock <cedricgrass at shockfamily.net>
> Date: Sat, 15 Jul 2006 13:43:49 -0700
> To: <grass-dev at grass.itc.it>
> Subject: [GRASS-dev] Using current grass gui.tcl in python programs.
> 
> Hi,
> 
> This might be a quick way to get up and running with playing with python
> development. It's fairly easy to use the current gui.tcl in python. Here's an
> example (copy / paste into python run in grass). This could all be bundled up
> and abstracted away to be more useful. I also stuck this snippit on the wiki
> at http://grass.gdf-hannover.de/wiki/GRASS_and_Python , so if you make
> improvements please share them here and there.
> 
> --Cedric
> 
> import Tkinter
> import os
> 
> # Startup (onde):
> 
> tk = Tkinter.Tk()
> tk.eval ("wm withdraw .")
> tk.eval ("source $env(GISBASE)/etc/gui.tcl")
> # Here you could do various things to change what the gui does
> # See gui.tcl and README.GUI
> 
> # Make a gui (per dialog)
> # This sets up a window for the command.
> # This can be different to integrate with tkinter:
> tk.eval ('set path ".dialog$dlg"')
> tk.eval ('toplevel .dialog$dlg')
> # Load the code for this command:
> fd = os.popen ("d.vect --tcltk")
> gui = fd.read()
> # Run it
> tk.eval(gui)
> dlg = tk.eval('set dlg') # This is used later to get and set
> 
> # Get the current command in the gui we just made:
> currentcommand = tk.eval ("dialog_get_command " + dlg)
> 
> # Set the command in the dialog we just made:
> tk.eval ("dialog_set_command " + dlg + " {d.vect map=roads}")
> 
> 




More information about the grass-dev mailing list