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!
I'm new in java programming, i have insert amounts in database in this Format exp : 1.100.200,00 but the subtraction of this amount give false result .
here is ...
So for this program im trying to print out the max height the projectile reaches and when i run the str on the object it dosent change the value to ...
Is C similar to C# (C-sharp); or are they completely different ? I was wondering if I should begin learning C# and the transition to C will be a tad ...