Python Forum
[Tkinter] tkinter best way to pass parameters to a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] tkinter best way to pass parameters to a function
#1
I want to pass 2 numbers to a function in tkinter.

The numbers are in a list. The default values are numbers = [10, 2]

When I tried using partial(calcGrowth, numbers[0], numbers[1]) I always got the default values, even after I entered new values.

So I tried this with lambda, seems to work.

Is it the best way to pass the parameters to a function in tkinter?

btn5 = tk.Button(frame1, text='calculate exponent', command=lambda: calcGrowth(numbers[0], numbers[1]))
btn5.grid(columnspan=2, column=0, row=3, sticky='w', pady=10)
Reply


Messages In This Thread
tkinter best way to pass parameters to a function - by Pedroski55 - Nov-16-2021, 01:18 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  pass a variable between tkinter and toplevel windows janeik 10 2,490 Jan-24-2024, 06:44 AM
Last Post: Liliana
  Using Tkinter inside function not working Ensaimadeta 5 5,162 Dec-03-2023, 01:50 PM
Last Post: deanhystad
  Tkinter won't run my simple function AthertonH 6 4,000 May-03-2022, 02:33 PM
Last Post: deanhystad
  how to add two numbers and pass the result to the next page in tkinter? pymn 7 4,405 Feb-15-2022, 04:40 AM
Last Post: pymn
  Creating a function interrupt button tkinter AnotherSam 2 5,616 Oct-07-2021, 02:56 PM
Last Post: AnotherSam
  [Tkinter] Have tkinter button toggle on and off a continuously running function AnotherSam 5 5,091 Oct-01-2021, 05:00 PM
Last Post: Yoriz
  tkinter get function finndude 2 3,008 Mar-02-2021, 03:53 PM
Last Post: finndude
  tkinter -- after() method and return from function -- (python 3) Nick_tkinter 12 7,624 Feb-20-2021, 10:26 PM
Last Post: Nick_tkinter
  function in new window (tkinter) Dale22 7 5,289 Nov-24-2020, 11:28 PM
Last Post: Dale22
Star [Tkinter] How to perform math function in different page of Tkinter GUI ravaru 2 4,642 Oct-23-2020, 05:46 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020