0
def windowforfriends():
    window = tk.Toplevel(root)
    frame = Frame(window, width=500, height=500)
    frame.pack()
    tk.Label(frame, text="Reader").grid(row=0)
    tk.Label(frame, text="# of friends").grid(row=1)

    e1 = tk.Entry(frame)
    e2 = tk.Entry(frame)

    e1.grid(row=0, column=1)
    e2.grid(row=1, column=1)
    tk.Button(frame, text='Show', command=friends()).grid(row=3, column=1,sticky=tk.W, pady=4)

So I have this function on the tk.button line called friends(), that takes in two arguments. The reader, and the number of friends.

So the command friends() calls the function, but I need the label of reader, and friends to be taken in as the two arguments needed for the command.

I have tried making a lambda function, like this:

tk.Button(frame,text="Show",command=lambda: friends(e1,e2).grid(row=3, column=1,sticky=tk.W, pady=4))

To take in e1 and e2 (which are the input boxes for the GUI) as the parameters, but now the button isnt showing on the GUI at all.

What am I doing wrong? Any insight would be very helpful.

  • As it stands you are missing a closing bracket:. `(e1,e2)).grid(...` and you should see a Traceback. [Edit] your question and show the Traceback. – stovfl Feb 17 '20 at 23:27
  • Does this answer your question? [How to pass arguments to a Button command in Tkinter?](https://stackoverflow.com/questions/6920302/how-to-pass-arguments-to-a-button-command-in-tkinter) – Guy Gangemi Feb 17 '20 at 23:37

0 Answers0