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):
        self.l=Label(top,text="Hello World")
    def cleanup(self):

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

    def popup(self):

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

if __name__ == "__main__":
  • 2
    I have never tested, but for what it's worth I read that Tkinter based widgets do not play nicely in ArcMap.
    – crmackey
    Commented Jun 11, 2015 at 18:59
  • as found here what youre saying is completely true, geonet.esri.com/thread/51876, however I really would love to have user input somehow, it doesn't have to be tkinter
    – Solaire
    Commented Jun 11, 2015 at 19:02
  • 1
    After reading your post again, you could try introducing a bit more logic into your script tool. For example, you could have an optional parameter that allows the user to enter any extra field names not found in the target feature using a String data type as a multiple input parameter.
    – crmackey
    Commented Jun 11, 2015 at 19:12
  • Im using a tkinter listbox of all fields, which the user can pick from .and its working since double clicking is possible even if focus is lost right after, I think it's more user friendly as well, since typos aren't possible.
    – Solaire
    Commented Jun 12, 2015 at 14:32

1 Answer 1


There is a base widget method called focus_force (see here) that will force focus to the specified application - this should capture user input. There is also a toplevel attribute called topmost which can be set (see here). After creating the window widget, you will need to call the method and set the attribute


window.wm_attributes("-topmost", 1)
  • I havn't tried that one yet, so just to make sure I'm applying it correctly, in the example I posted I need to add the following line: self.top.focus.force() in function __init__()
    – Solaire
    Commented Jun 11, 2015 at 18:08
  • in that case it doesn't work, I also tried grab_set(), and grab_set_global()
    – Solaire
    Commented Jun 11, 2015 at 18:22
  • 1
    @Solaire Try doing it just after the line of code self.w=popupWindow(self.master)
    – papadoo
    Commented Jun 11, 2015 at 19:52
  • I added the line self.w.force_focus() where you suggested and it doesn't work.
    – Solaire
    Commented Jun 12, 2015 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.