This can be done using a lambda, like so:
button = Tk.Button(master=frame, text='press', command= lambda: action(someNumber))
This is a simple way to bind the argument without an explicit wrapper method or modifying the original action.
This can be done using a lambda, like so:
button = Tk.Button(master=frame, text='press', command= lambda: action(someNumber))
This is a simple way to bind the argument without an explicit wrapper method or modifying the original action.
This can also be done by using partial from the standard library functools, like this:
from functools import partial
#(...)
action_with_arg = partial(action, arg)
button = Tk.Button(master=frame, text='press', command=action_with_arg)
[Tkinter] Button command is executed as soon as the program is run without pressing the button
(TKINTER) How would I go about closing a window right after a new Toplevel window is opened.
Passing variables into Tkinter button click event
Reassigning Global Variables with Button Commands
Videos
I'm trying to create a button that shows a label and entry widget when pressed. However, the button, label and entry widget all show up without the button even being pressed. The following is my code:
from tkinter import *
main = Tk()
main.title('Test')
lbl1 = Label(main, text= 'BUTTON PRESSED')
ent1= Entry(main)
def onclick():
lbl1.grid(row=1, column= 0, padx=35, pady=5)
ent1.grid(row=3,column=0)
btn1 = Button(main, text = 'Press to Begin', command= onclick())
btn1.grid(row=0, column=0, padx=30, pady=4)
main.mainloop()