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

Cedric Shock cedricgrass at shockfamily.net
Sat Jul 15 16:43:49 EDT 2006


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