Just van Rossum | a840fca | 1999-09-26 12:25:06 +0000 | [diff] [blame] | 1 | import W |
| 2 | |
| 3 | # define some callbacks |
| 4 | def callback(): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame^] | 5 | window.close() |
Just van Rossum | a840fca | 1999-09-26 12:25:06 +0000 | [diff] [blame] | 6 | |
| 7 | def checkcallback(value): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame^] | 8 | print "hit the checkbox", value |
Just van Rossum | a840fca | 1999-09-26 12:25:06 +0000 | [diff] [blame] | 9 | |
| 10 | def radiocallback(value): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame^] | 11 | print "hit radiobutton #3", value |
Just van Rossum | a840fca | 1999-09-26 12:25:06 +0000 | [diff] [blame] | 12 | |
| 13 | def scrollcallback(value): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame^] | 14 | widget = window.hbar |
| 15 | if value == "+": |
| 16 | widget.set(widget.get() - 1) |
| 17 | elif value == "-": |
| 18 | widget.set(widget.get() + 1) |
| 19 | elif value == "++": |
| 20 | widget.set(widget.get() - 10) |
| 21 | elif value == "--": |
| 22 | widget.set(widget.get() + 10) |
| 23 | else: # in thumb |
| 24 | widget.set(value) |
| 25 | print "scroll...", widget.get() |
Just van Rossum | a840fca | 1999-09-26 12:25:06 +0000 | [diff] [blame] | 26 | |
| 27 | def textcallback(): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame^] | 28 | window.et3.set(window.et1.get()) |
Just van Rossum | a840fca | 1999-09-26 12:25:06 +0000 | [diff] [blame] | 29 | |
| 30 | def cancel(): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame^] | 31 | import EasyDialogs |
| 32 | EasyDialogs.Message("Cancel!") |
Just van Rossum | a840fca | 1999-09-26 12:25:06 +0000 | [diff] [blame] | 33 | |
| 34 | # make a non-sizable window |
| 35 | #window = W.Window((200, 300), "Fixed Size") |
| 36 | |
| 37 | # make a sizable window |
| 38 | window = W.Window((200, 300), "Variable Size!", minsize = (200, 300)) |
| 39 | |
| 40 | # make some edit text widgets |
| 41 | window.et1 = W.EditText((10, 10, 110, 110), "Hallo!", textcallback) |
| 42 | window.et2 = W.EditText((130, 40, 60, 30), "one!") |
| 43 | window.et3 = W.EditText((130, 80, -10, 40), "two?") |
| 44 | |
| 45 | # a button |
| 46 | window.button = W.Button((-70, 10, 60, 16), "Close", callback) |
| 47 | |
| 48 | # a checkbox |
Just van Rossum | fb3e54f | 2001-06-19 21:38:42 +0000 | [diff] [blame] | 49 | window.ch = W.CheckBox((10, 130, 160, 16), "Check (command \xa4)", checkcallback) |
Just van Rossum | a840fca | 1999-09-26 12:25:06 +0000 | [diff] [blame] | 50 | |
| 51 | # set of radio buttons (should become easier/nicer) |
| 52 | thebuttons = [] |
| 53 | window.r1 = W.RadioButton((10, 150, 180, 16), "Radio 1 (cmd 1)", thebuttons) |
| 54 | window.r2 = W.RadioButton((10, 170, 180, 16), "Radio 2 (cmd 2)", thebuttons) |
| 55 | window.r3 = W.RadioButton((10, 190, 180, 16), "Radio 3 (cmd 3)", thebuttons, radiocallback) |
| 56 | window.r1.set(1) |
| 57 | |
| 58 | # a normal button |
| 59 | window.cancelbutton = W.Button((10, 220, 60, 16), "Cancel", cancel) |
| 60 | |
| 61 | # a scrollbar |
| 62 | window.hbar = W.Scrollbar((-1, -15, -14, 16), scrollcallback, max = 100) |
| 63 | |
| 64 | # some static text |
| 65 | window.static = W.TextBox((10, 260, 110, 16), "Schtatic") |
| 66 | |
| 67 | # bind some keystrokes to functions |
Just van Rossum | fb3e54f | 2001-06-19 21:38:42 +0000 | [diff] [blame] | 68 | window.bind('cmd\xa4', window.ch.push) |
Just van Rossum | a840fca | 1999-09-26 12:25:06 +0000 | [diff] [blame] | 69 | window.bind('cmd1', window.r1.push) |
| 70 | window.bind('cmd2', window.r2.push) |
| 71 | window.bind('cmd3', window.r3.push) |
| 72 | window.bind('cmdw', window.button.push) |
| 73 | window.bind('cmd.', window.cancelbutton.push) |
| 74 | |
| 75 | window.setdefaultbutton(window.button) |
| 76 | # open the window |
| 77 | window.open() |
| 78 | |
| 79 | if 0: |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame^] | 80 | import time |
| 81 | for i in range(20): |
| 82 | window.et2.set(repr(i)) |
| 83 | #window.et2.SetPort() |
| 84 | #window.et2.draw() |
| 85 | time.sleep(0.1) |