I have two buttons and one function.When a user click button1 or button2 program should call the function and the function will write to the screen whic button clicked.I mean if i click button1 there will write "Button1 clicked" on the screen.All in al i want to learn how can learn that, which button called my function(i dont want more than 1 function).
Which GUI toolkit are you using?
With most GUI's you can pass parameters with the function call, so button 1 would use button_press("1") and button 2 would use button_press("2"). If this does not work with the graphics you are using, use a pass-through function
def button_pressed(): ##do common stuff here def button_one(): print "button one pressed" button_pressed() def button_two(): print "button two pressed" button_pressed()
Here is an example using the common Tkinter GUI toolkit ...
# Tkinter, show the button that has been clicked import Tkinter as tk def click(event): s = "clicked: " + event.widget.cget("text") root.title(s) root = tk.Tk() root.geometry("300x50+30+30") b1 = tk.Button(root, text="button1") b1.bind("<Button-1>", click) b1.pack() b2 = tk.Button(root, text="button2") b2.bind("<Button-1>", click) b2.pack() root.mainloop()
Thank you very much! This was just what I was looking for in order to call a function from a button!
Hi all! I need help understanding what my teacher expects from this project.
Here is the link to the instructions for the project: http://cs.ecu.edu/~karl/2530/spr18/Assn/Assn5/assn5.html
I wrote a little bit of ...
Anyone have a shell script to remove controlM character from all the files in a directory
Define a class named Pair where the data(state) part contains two double-typed
numbers, num1 and num2. The method(behaviour) part contain the following methods:
o getSum() – returns the result of ...