0

hello guys I want to ask if anyone know how I can save the path from a file to a string so then I can use it to a different definition as a input. TNX here is my code and I want to save the paths from def pst,vst and use them to def MDB.

# modules
from Tkinter import * 
import tkFileDialog
import sys

# definitiion
def MDB():
    import createMDB
def pst():
    geo= tkFileDialog.askopenfilename(filetypes = (("ShapeFiles", "*.shp"), ("All files", "*")))
    T.insert(END, "Load PST Path\n")
def vst():
    kath = tkFileDialog.askopenfilename(filetypes = (("ShapeFiles", "*.shp"), ("All files", "*")))
    T.insert(END, "Load VST Path\n")

# application
app=Tk()
app.wm_title("GST1606")
# grid
w=Canvas(app,width=100,height=50)
w.pack()
# menu
menu=Menu(app)
app.config(menu=menu)
submenu=Menu(menu)
menu.add_cascade(label="Browse", menu=subme
                 nu)
submenu.add_command(label="Pst", command=pst)
submenu.add_command(label="Vst", command=vst)
sub=Menu(menu)

menu.add_cascade(label="Execute", menu=sub)
sub.add_command(label="Create MDB", command=MDB)
# buttons
Button1=Button(app,text="create MDB", command=MDB)
Button1.pack(padx=50, pady=50)
# txt
T = Text(app, height=2, width=30)
T.pack()

# freeze
mainloop()

1 Answers1

0

You can define your path as a global variable so that it can be used in different functions:

geo = "..."

def MDB():
    print(geo)
def pst():
    global geo
    geo = tkFileDialog.askopenfilename()

Or you can structure your GUI in a class, which is especially useful if your GUI gets more complex. See:

Josselin
  • 2,593
  • 2
  • 22
  • 35