I have a project in Python, which is reading a text file and took some information from that file and draw a graph. There is a button that allows the user to take a picture of the graph. The problem is when you press the save polt button, it opens a window asking the user to enter a name for the image. but every time I press Ok the window opening again without to close the old one.
Here is first function will call when click on the save plot button.
def save_graph():
print('saving')
f = fig1
popup()
e = input
x = ("{}".format(e.get()))
b.wait_variable(e)
if flag_clear_graph != 0:
if input != '':
f.savefig(x + ".png")
print(x)
log_meg("[INFORMATION]: Graph saved under name " + x + ".png")
else:
log_meg("[WARNING]: Please choose a name for the graph.")
else:
log_meg("[WARNING]: Plot a graph before saving.")
top.destroy()
This part from the code I took it from this this website Creating a popup message box with an Entry field
def popup():
w=name_plot()
b["state"] = "disabled"
#b.wait_variable(w.top)
#master.wait_window(w.top)
#master.wait_window
b["state"] = "normal"
def name_plot():
global top, e, b
print("")
input = StringVar()
top = Toplevel()
top.iconbitmap('logo.ico')
l = Label(top, text="Please enter a name to save the graph by it")
l.grid(column=0, row=0, padx=10, pady=10, sticky='ew')
e = Entry(top, textvariable=input)
e.grid(column=0, row=1, padx=10, pady=10, sticky='ew')
# b = Button(top, text='Ok', command=lambda: save_graph(input)) # I tried this as well
b = Button(top, text='Ok', command=save_graph)
b.grid(column=0, row=2, padx=10, pady=10, sticky='ew')
by the way, I tried before and used the same code and it was working perfectly, it was printing the result as well.
x = ("{}".format(e.get()))
AttributeError: 'builtin_function_or_method' object has no attribute 'get'
So please can anyone help me with this.
Thanks in advance.