Simple windowed application

From Rosetta Code
Revision as of 13:55, 3 March 2007 by 151.37.66.154 (talk)
Task
Simple windowed application
You are encouraged to solve this task according to the task description, using any language you may know.

This tasks asks to create a window with a label that says "There have been no clicks yet" and a button that says "click me". Upon clicking the button with the mouse, the label should change and show the number of times the button has been clicked.

IDL

pro counter, ev
  widget_control, ev.top, get_uvalue=tst
  tst[1] = tst[1]+1
  widget_control, tst[0], set_value="Number of clicks: "+string(tst[1],format='(i0)')
  widget_control, ev.top, set_uvalue=tst
end
 
id = widget_base(title = 'Window Title',column=1)
ld = widget_label(id, value = 'There have been no clicks yet.')
widget_control, /realize, id, set_uvalue=[ld,0]
dummy = widget_button(id,value=' Click Me ',event_pro='counter')
xmanager, "Simple", Id
 
end

Tcl

pack [label .l -text "There have been no clicks yet."]
set count 0
pack [button .b -text " Click Me " -command upd]
proc upd {} {.l configure -text "Number of clicks: [incr ::count]."}

Python

With Tkinter:

from Tkinter import Tk, Label, Button

def update_label():
    global n
    n += 1
    l["text"] = "Number of clicks: %d" % n

w = Tk()
n = 0
l = Label(w, text="There have been no clicks yet")
l.pack()
Button(w, text="click me", command=update_label).pack()
w.mainloop()