"create a group of radio buttons that launch dialog demos"
from tkinter import * # get base widget set from dialogTable import demos # button callback handlers from quitter import Quitter # attach a quit object to "me"
class Demo(Frame): def init(self, parent=None, **options): Frame.init(self, parent, **options) self.pack() Label(self, text="Radio demos").pack(side=TOP) self.var = StringVar() for key in demos: Radiobutton(self, text=key, command=self.onPress, variable=self.var, value=key).pack(anchor=NW) self.var.set(key) # select last to start Button(self, text='State', command=self.report).pack(fill=X) Quitter(self).pack(fill=X)
代码语言:javascript复制def onPress(self):
pick = self.var.get()
print('you pressed', pick)
print('result:', demos[pick]())
def report(self):
print(self.var.get())
if name == 'main': Demo().mainloop()