tkinter button command with arguments
from functools import partial
#
#
def function_name(arg1):
print(arg1)
#
#tkinter codes for GUI
#
buttonExample = tk.Button(main, text="Button", command=partial(function_name, argument1))
tkinter button command with arguments
from functools import partial
#
#
def function_name(arg1):
print(arg1)
#
#tkinter codes for GUI
#
buttonExample = tk.Button(main, text="Button", command=partial(function_name, argument1))
tkinter bind function with arguments
import tkinter as tk
class SampleApp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.frame = tk.Frame(self)
self.frame.pack()
self.button = tk.Button(self.frame, text="click me",
command=lambda a=1, b=2, c=3:
self.rand_func(a, b, c))
self.button.pack()
self.frame.bind("<Return>",
lambda event, a=10, b=20, c=30:
self.rand_func(a, b, c))
# make sure the frame has focus so the binding will work
self.frame.focus_set()
def rand_func(self, a, b, c):
print "self:", self, "a:", a, "b:", b, "c:", c
print (a+b+c)
app = SampleApp()
app.mainloop()
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us