How can I let the Tkinter Button command do more than one function?
Use something like:
def callback(): functionone(x) #tab me woot functiontwo(y) #tab me woot
As a base for your callback code.
* Sorry if this is incorrect; I'm new to python! vegaseat, please correct me if I'm wrong.
Yes linux, that would be the simplest way to do it!
Python allows you to pass functions as arguments to a function. This code might give you more flexibility ...
# giving a Tkinter Button command two (or multiple) functions to run import Tkinter as tk def do_two(s, f1, f2): """run 2 functions f1 and f2""" f1(s) # after 2 sec run function f2 root.after(2000, f2) root = tk.Tk() root.title('click me') s = '123' f1 = root.title f2 = root.destroy # using lambda to pass string s and two functions f1 and f2 as arguments q1 = lambda: do_two(s, f1, f2) b2 = tk.Button(root, text=" click to show 123, then after 2 sec quit ", command=q1) b2.pack() root.mainloop()
There's one other way that I've found, although sometimes it feels like cheating: bind another function to the mouseclick of that button.
button = Button(text="Two Functions", command=f1) button.pack() button.bind('<ButtonRelease-1>', f2) button.focus_force()
Thus the usual command is to perform
f1 , while when the mouse has clicked the button and released,
As far as I can tell, you can only bind one function to a particular event. Although I suppose you could bind a third function to the click (rather than the release), I've found that it tends to be jarring for the user at times.
I've been searching for another way around this problem for ages, to no avail...
I have an Epson receipt printer (Model number: TM-T88V), but I cannot use it. I do not have a POS (point of sale) software that will let me do what ...
I have a datatable in Winforms.
I am currently trying to find the max and min values for each of the columns for each row. My table layout is like ...
This code generates an ascii maze of up to size 30x30. If you try to generate a larger maze then you will likely run out of stack space. There is ...