I have this function inside one of my python scripts which throws up a Tkinter simple dialog screen to ask for some simple user-input. The function works. However, there are 2 problems with it.
- It opens up two windows, while all I need is one. But if I remove the master = Tk() I get the error:
AttributeError: 'NoneType' object has no attribute 'winfo_viewable'
It would be nice to at one point figure that one out, but my main problem however is the second one:
- Whenever the simple dialog screen turns up, I have to click it first before it gets activated, which is annoying. To fix it I tried the solutions offered here and here but they do not work. The first link didn't do anything for me at all, the second link helped me to lift the master.Tk() window to the front, but that is not what I need. I need the simple dialog window to become the topmost window and I need it to be auto-activated so that when I run my code and the screen pops-up I can automatically type in it without having to click on it first.
Any help would be greatly appreciated!
My code:
def getUser():
master = Tk()
newList2=str(newList).replace(", ","\n")
for ch in ['[',']',"'"]:
if ch in newList2:
newList5=newList2.replace(ch,"")
userNr=simpledialog.askinteger("Enter user number", newList2)
chosenUsernr= userNr - 1
global chosenUsernrdef
chosenUsernrdef = chosenUsernr
master.destroy()