Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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()
Comment

PREVIOUS NEXT
Code Example
Python :: division operators in python 
Python :: python loop function 
Python :: python numpy euler 
Python :: prime numbers 1 to input 
Python :: python for loop inside list 
Python :: smma python 
Python :: how to add background and font color to widget in tkinter 
Python :: sklearn impute 
Python :: get linkinstance revit api 
Python :: stackoverflow - import data on colabs 
Python :: code error correction 
Python :: generate 50 characters long for django 
Python :: Use in in django while preserving order 
Python :: deduplication jaccard python 
Python :: sys executable juypter is incorrect visual code 
Python :: run shell script to yaml file 
Shell :: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation 
Shell :: Starting Apache...fail. 
Shell :: refusing to merge unrelated histories 
Shell :: docker remove none images 
Shell :: brew install gcloud 
Shell :: linux find files larger than 1gb 
Shell :: kill all docker processes force 
Shell :: git command show current repo 
Shell :: reload zshrc 
Shell :: m1 pod install 
Shell :: install ping docker 
Shell :: jq on mac 
Shell :: linux which process is using a port 
Shell :: git log graph 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =