0

I am using a simpledialog box to pop up and enter information within a function. I have to first click on the box before typing my input, which is too slow for what I want to use it for. Is it possible to run the function, have the simpledialog box pop up and type immediately without clicking the box?

Please find the relevant code lines I'm using below:

%matplotlib notebook
import tkinter as tk
from tkinter import simpledialog
d1 = []
dots = []

fig,ax = plt.subplots(figsize=(10,20))

ROOT = tk.Tk()

ROOT.withdraw()

def func1(event):
    if event.inaxes:
        dots.append((event.xdata, event.ydata))
        if len(dots) == 2:
            ax.plot([dots[0][0], dots[1][0]],
                    [dots[0][1], dots[1][1]], 'yo-')
            amount = simpledialog.askstring(title="Amount", prompt="Type Number:")
            d1.append([dots[0], dots[1], amount])
            dots[:] = []

        fig.canvas.draw()

Thanks in advance.

j_4321
  • 15,431
  • 3
  • 34
  • 61
toothsie
  • 245
  • 3
  • 10

1 Answers1

0

Did some searching around. Found a person with the same problem here who solved it and wrote the solution along with references.

How to auto-activate a tkinter simpledialog pop-up window?

To sum up, the person created a custom askinteger box, and then used the following code.

def getUser():       
    newList2=str(newList).replace(", ","\n")
    askInteger = CustomAskInteger("Enter user number", newList2)
    #since it is a Tk() instance, you can do lift/focus/grab_set etc. on this
    askInteger.lift()
    askInteger.mainloop()
    userNr = askInteger.value

The idea is that he created the askinteger box into a new window, and then used the lift() function on it. The lift() function only works on windows, which is why it wouldn't work on the regular askinteger.

I think this should solve your problem.

Storm Claw
  • 59
  • 2
  • 8