Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Arcpy scripts run time dialog keeps deactivating tkinter window

$
0
0

I’m using tkinter in my scripts to get field names of the user in case the hard coded field names were not found in the target feature.

it runs from python IDE, but when run from arcmaps toolbox the interface keeps refreshing making it impossible to focus on the input message box generated from the script.

Is there a way to keep focus on the generated dialog so the user can type in the information? I can post my script if needed. or is there less messy way to get a string value from the user?

I’m using something similar to this :

from Tkinter import *
import sys

class popupWindow(object):
    def __init__(self,master):
        top=self.top=Toplevel(master)
        self.l=Label(top,text="Hello World")
        self.l.pack()
        self.e=Entry(top)
        self.e.pack()
        self.b=Button(top,text='Ok',command=self.cleanup)
        self.b.pack()
    def cleanup(self):
        self.value=self.e.get()
        self.top.destroy()

class mainWindow(object):
    def __init__(self,master):
        self.master=master
        self.b=Button(master,text="click me!",command=self.popup)
        self.b.pack()
        self.b2=Button(master,text="print value",command=lambda: sys.stdout.write(self.entryValue()+'n'))
        self.b2.pack()

    def popup(self):
        self.w=popupWindow(self.master)
        self.master.wait_window(self.w.top)

    def entryValue(self):
        return self.w.value


if __name__ == "__main__":
    root=Tk()
    m=mainWindow(root)
    root.mainloop()

Viewing all articles
Browse latest Browse all 767

Trending Articles