0

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.

Illustrative image

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.

Wasim
  • 13
  • 3
  • `save_graph` (the button function) calls `popup`, which calls `name_plot`, which creates another `Entry`. It doesn't seem like `pop_up` should call `name_plot`, since the uncommented code isn't using `w` (and `name_plot` isn't returning anything anyway). – Carcigenicate Dec 07 '20 at 21:19
  • For the title question though, it seems like you want to change `save_graph` to `def save_graph(name):`, then `command=save_graph, args=(input,)`, then use `name` inside `save_graph`. Also, don't call your variable `input`. That's a built-in function. – Carcigenicate Dec 07 '20 at 21:24

0 Answers0