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...
So I have a JTextfield in the cells of 1 of the columns in my JTable
I want to allow only numbers and up to one dot/period. Doesant ...
vb.Net - Regular Expression Tester
Every now and then I find another use for a regular expression. For those not familiar with regular expressions, they can be as cryptic to ...
I'm trying to build a client and a server in the same program. For example, user 1 sends a packet of data to user 2, user 2 after receiving the ...