0

How can I return a parameter after using a button in tkinter?

def read(excelfile):
    data = pd.ExcelFile("rsc/" + excelfile + ".xlsx")
    file = pd.read_excel(data)
    return file

browse_btn = tk.Button(root, text="Browse", command=lambda:read(), bg="#20bebe", fg="white", width=15, height=2)

It won't keep working in the function def read().

acw1668
  • 40,144
  • 5
  • 22
  • 34
Singh
  • 1
  • There is no point in returning from a button `command`. You can use global variables to pass the result to your main code – TheLizzard Apr 26 '21 at 09:59
  • Or better append that variables to a list so that You don't have to use global variables (because they are not good and a bad practice: https://stackoverflow.com/questions/19158339/why-are-global-variables-evil) – Matiiss Apr 26 '21 at 10:19
  • @Matiiss First of all the list will be a global variable second of all global variables aren't bad practise if you are using functional programming. – TheLizzard Apr 26 '21 at 10:25
  • `read()` does return `file` but it is discarded if the function is used as `command` option directly. If you use `lambda: print(read())`, you should see something in the console. – acw1668 Apr 26 '21 at 10:35

0 Answers0