blob: ae47550e3aadc496f85e69400ef98df82decd27b [file] [log] [blame]
Just van Rossuma840fca1999-09-26 12:25:06 +00001"""Simple W demo -- shows how to make a window, and bind a function to a "key" event."""
2
3import W
4
5# key callback function
6def tester(char, event):
Tim Peters182b5ac2004-07-18 06:16:08 +00007 text = "%r\r%d\r%s\r%s" % (char, ord(char), hex(ord(chart)), oct(ord(char)))
8 window.keys.set(text)
Just van Rossuma840fca1999-09-26 12:25:06 +00009
10# close callback
11def close():
Tim Peters182b5ac2004-07-18 06:16:08 +000012 window.close()
Just van Rossuma840fca1999-09-26 12:25:06 +000013
14# new window
15window = W.Dialog((180, 100), "Type a character")
16
17# make a frame (a simple rectangle)
18window.frame = W.Frame((5, 5, -5, -33))
19
20# some labels, static text
21window.captions = W.TextBox((10, 9, 43, -36), "char:\rdecimal:\rhex:\roctal:")
22
23# another static text box
24window.keys = W.TextBox((60, 9, 40, -36))
25
26# a button
27window.button = W.Button((-69, -24, 60, 16), "Done", close)
28
29# bind the callbacks
30window.bind("<key>", tester)
31window.bind("cmdw", window.button.push)
32
33# open the window
34window.open()