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 was wondering if it was possible to create a software like visual studio (in addition simple, obviously). We could program in vb.net, c ++, etc.
Write a looping program for Theater Seating selection
The program will display the theater seating (shown later) and prompt the user to select a seat to purchase using the row ...
Hi Maam and Sir.
I need your expertise on vb.net.
I have two data grid with database on their own. I want to copy/update the data from one database to ...