diff options
author | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@localhost> | 2011-05-03 11:25:13 +0000 |
commit | 458120dd40db6b4df55a4e96b650e16798ef06a0 (patch) | |
tree | 8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/src/cmd/python/Demo/tkinter/guido/switch.py | |
parent | 3a742c699f6806c1145aea5149bf15de15a0afd7 (diff) |
add hg and python
Diffstat (limited to 'sys/src/cmd/python/Demo/tkinter/guido/switch.py')
-rw-r--r-- | sys/src/cmd/python/Demo/tkinter/guido/switch.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/sys/src/cmd/python/Demo/tkinter/guido/switch.py b/sys/src/cmd/python/Demo/tkinter/guido/switch.py new file mode 100644 index 000000000..3b58f7ce4 --- /dev/null +++ b/sys/src/cmd/python/Demo/tkinter/guido/switch.py @@ -0,0 +1,55 @@ +# Show how to do switchable panels. + +from Tkinter import * + +class App: + + def __init__(self, top=None, master=None): + if top is None: + if master is None: + top = Tk() + else: + top = Toplevel(master) + self.top = top + self.buttonframe = Frame(top) + self.buttonframe.pack() + self.panelframe = Frame(top, borderwidth=2, relief=GROOVE) + self.panelframe.pack(expand=1, fill=BOTH) + self.panels = {} + self.curpanel = None + + def addpanel(self, name, klass): + button = Button(self.buttonframe, text=name, + command=lambda self=self, name=name: self.show(name)) + button.pack(side=LEFT) + frame = Frame(self.panelframe) + instance = klass(frame) + self.panels[name] = (button, frame, instance) + if self.curpanel is None: + self.show(name) + + def show(self, name): + (button, frame, instance) = self.panels[name] + if self.curpanel: + self.curpanel.pack_forget() + self.curpanel = frame + frame.pack(expand=1, fill="both") + +class LabelPanel: + def __init__(self, frame): + self.label = Label(frame, text="Hello world") + self.label.pack() + +class ButtonPanel: + def __init__(self, frame): + self.button = Button(frame, text="Press me") + self.button.pack() + +def main(): + app = App() + app.addpanel("label", LabelPanel) + app.addpanel("button", ButtonPanel) + app.top.mainloop() + +if __name__ == '__main__': + main() |