Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 1 | from Tkinter import * |
| 2 | |
| 3 | # shows how to make a slider, set and get its value under program control |
| 4 | |
| 5 | |
| 6 | class Test(Frame): |
| 7 | def print_value(self, val): |
Collin Winter | 6f2df4d | 2007-07-17 20:59:35 +0000 | [diff] [blame^] | 8 | print("slider now at", val) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 9 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 10 | def reset(self): |
| 11 | self.slider.set(0) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 12 | |
| 13 | def createWidgets(self): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 14 | self.slider = Scale(self, from_=0, to=100, |
| 15 | orient=HORIZONTAL, |
| 16 | length="3i", |
| 17 | label="happy slider", |
| 18 | command=self.print_value) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 19 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 20 | self.reset = Button(self, text='reset slider', |
| 21 | command=self.reset) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 22 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 23 | self.QUIT = Button(self, text='QUIT', foreground='red', |
| 24 | command=self.quit) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 25 | |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 26 | self.slider.pack(side=LEFT) |
| 27 | self.reset.pack(side=LEFT) |
| 28 | self.QUIT.pack(side=LEFT, fill=BOTH) |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 29 | |
| 30 | def __init__(self, master=None): |
Tim Peters | 182b5ac | 2004-07-18 06:16:08 +0000 | [diff] [blame] | 31 | Frame.__init__(self, master) |
| 32 | Pack.config(self) |
| 33 | self.createWidgets() |
Guido van Rossum | 35820f7 | 1994-10-07 09:55:26 +0000 | [diff] [blame] | 34 | |
| 35 | test = Test() |
| 36 | test.mainloop() |