def __init__(self, parent=None): Frame.__init__(self, parent) # create game directions lab = Label(self, text="Throw the dice!", width=20, height=3) lab.pack(side=TOP, fill=BOTH) # create a frame for dice throw res = Label(self, width=20, height=10) res.config(text='hi') res.pack(side=TOP) # create an entry form for number of dice form = Frame(self) form.pack(side=TOP, fill=X) ent_lab = Label(form, text="How many dice?", width=15) ent_lab.pack(side=LEFT) ent = Entry(form) var = IntVar() ent.config(textvariable=var) ent.pack(side=LEFT) # create a button that executes a roll but = Button(form, text="Roll", width=5, height=3) but.config(command=(lambda: self.toss(var.get(), res))) but.pack(side=RIGHT, fill=X, expand=YES) # create a button that quits program quit = Quitter(self) quit.pack(side=TOP, fill=X, expand=YES)
def __init__(self, parent=None, **options): Frame.__init__(self, parent, **options) self.pack() Label(self, text="Scale demos").pack() self.var = IntVar() Scale( self, label='Pick demo number', command=self.onMove, # catch moves variable=self.var, # reflects position from_=0, to=len(demos) - 1).pack() Scale( self, label='Pick demo number', command=self.onMove, # catch moves variable=self.var, # reflects position from_=0, to=len(demos) - 1, length=200, tickinterval=1, showvalue=YES, orient='horizontal').pack() Quitter(self).pack(side=RIGHT) Button(self, text="Run demo", command=self.onRun).pack(side=LEFT) Button(self, text="State", command=self.report).pack(side=RIGHT)
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, # muestra en consola el evento que ha sucedido variable=self.var, value=key).pack(anchor=NW) self.var.set(key) # select last to start # valor por defecto para la variable tkinter que mostrará el método report Button(self, text='State', command=self.report).pack(fill=X) Quitter(self).pack(fill=X)
def __init__(self, parent=None): Frame.__init__(self, parent) # create a top box to tell the story story = """ Are you ready to travel... INTO THE DALEK?""" story_box = Text(self, bd=2, height=20, width=80) story_box.insert(1.0, story) story_box.config(bg='navy', fg='gold') story_box.config(bd=2, relief=SUNKEN) story_box.pack(side=TOP, expand=YES, fill=BOTH, padx=10, pady=10) # create an action box to hold the games action_box = Frame(self, height=10, width=50) action_box.config(bg='orange') action_box.pack(side=TOP, expand=YES, fill=BOTH) # create play again and quit buttons quit_space = Frame(self) again_but = Button(quit_space, text='Play') again_but.config( command=(lambda: self.start_game(story_box, action_box))) again_but.pack(side=LEFT, padx=10, pady=10) quit_but = Quitter(quit_space).pack(side=RIGHT) quit_space.pack(side=TOP, fill=X)
def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Label(self, text="Dialog picker demo - class").pack() Button(self, text="Run demo", command=self.pickDemo).pack(side=LEFT) Quitter(self).pack(side=RIGHT) self.index = -1
def __init__(self, parent=None, **options): Frame.__init__(self, parent, **options) self.pack() Label(self, text='按钮组', font=('times', 16, 'bold')).pack() for (key, value) in demos.items(): Button(self, text=key, command=value).pack(side=TOP, fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH)
def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() for (key, value) in demos.items(): func = (lambda self=self, name=key: self.printit(name)) Button(self, text=key, command=func).pack(side=TOP, fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH)
def tools(self): frm = Frame(self) frm.pack(side=RIGHT) Button(frm, text='State', command=self.report).pack(fill=X) # al hacer clic sobre el botón State, se ejecuta el manejador report => # muestra el valor de todas las variables tkinter definidas por el checkbutton Quitter(frm).pack(fill=X)
def __init__(self, parent=None, **options): Frame.__init__(self, parent, **options) self.pack() Label(self, text='Basic demos').pack() for (key, value) in demos.items(): Button(self, text=key, command=value).pack(side=TOP, fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH)
def __init__(self, parent=None): win = Frame(parent) win.pack() Label(win, text="Dialog picker demo - alt class").pack() Button(win, text="Run demo", command=self.pickDemo).pack(side=LEFT) Quitter(win).pack(side=RIGHT) self.index = -1
def __init__(self, master=None, cnf={}, **kw): super(Demo, self).__init__(master, cnf={}, **kw) self.pack() Label(master=self, text='Basic demos').pack() for (key, value) in demos.items(): Button(master=self, text=key, command=value).pack(side=TOP, fill=BOTH) Quitter(master=self).pack(side=TOP, fill=BOTH)
def __init__(self,parent=None,**options): Frame.__init__(self,parent,**options) self.pack() Label(self,text="Basic Demos").pack() for(key,value) in demos.items(): func = (lambda key=key:self.printit(key)) Button(self,text=key,command=func).pack(side=TOP,fill=BOTH) Quitter(self).pack(side=TOP,fill=BOTH)
def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Label(self, text='Basic demos').pack() for key in demos: func = (lambda key=key: self.printit(key)) #!!!! Button(self, text=key, command=func).pack(side=TOP, fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH)
def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() # Label(self, text="Basic demos").pack() for (key, value) in demos.items(): Button(self, text=key, command=value).pack(side=TOP, fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH) Label(self, text="Basic demos").pack()
def tools(self): ''' Builds the buttons on the right ''' frm = Frame(self) frm.pack(side=RIGHT) Button(frm, text='State', command=self.report).pack(fill=X) Quitter(frm).pack(fill=X)
def __init__(self, parent=None, **options): Frame.__init__(self, parent, **options) self.pack() Label(self, text='Basic dmons').pack() for (k, v) in demos.items(): Button(self, text=k, command=(lambda k=k: self.printit(k))).pack(side=TOP, fill=BOTH) # func = (lambda k=k: self.printit(k)) # Button(self, text=k, command=func).pack(side=TOP, fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH)
def __init__(self, master=None, **options): super(Demo, self).__init__(master, **options) self.pack() Label(master=self, text='Basic demos').pack() for key in demos: func = (lambda key=key: self.printit(key)) Button(master=self, text=key, command=func).pack(side=TOP, fill=BOTH) Quitter(master=self).pack(side=TOP, fill=BOTH)
def __init__(self, parent=None, **options): Frame.__init__(self, parent, **options) self.pack() Label(self, text="Basic demos").pack() # label on top of window for (key, value ) in demos.items(): # builds the list of buttons from 'demos' Button(self, text=key, command=value).pack(side=TOP, fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH) # separate quit button from import
def __init__(self, master=None, file=None, cnf={}, **kw): super(SimpleEditor, self).__init__(master, file=file) frame = Frame(master) frame.pack(fill=X) Button(frame, text='Save', command=self.onSave).pack(side=LEFT) Button(frame, text='Cut', command=self.onCut).pack(side=LEFT) Button(frame, text='Paste', command=self.onPaste).pack(side=LEFT) Button(frame, text='Find', command=self.onFind).pack(side=LEFT) Quitter(frame).pack(side=LEFT) self.text.config(font=('courier', 9, 'normal'))
def __init__(self, parent=None, file=None): frm = Frame(parent) frm.pack(fill=X) Button(frm, text='Save', command=self.onSave).pack(side=LEFT) Button(frm, text='Cut', command=self.onCut).pack(side=LEFT) Button(frm, text='Paste', command=self.onPaste).pack(side=LEFT) Button(frm, text='Find', command=self.onFind).pack(side=LEFT) Quitter(frm).pack(side=LEFT) ScrolledText.__init__(self, parent, file=file) self.text.config(font=('courier', 12, 'normal'))
def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Label(self, text="Basic demos").pack() for key in demos: func = (lambda key=key: self.printit(key)) #func = (lambda self=self, name=key: self.printit(name)) #func = (lambda handler=self.printit, name=key: handler(name)) Button(self, text=key, command=func).pack(side=TOP, fill=BOTH) Quitter(self).pack(side=TOP, fill=BOTH)
def __init__(self, parent=None): Frame.__init__(self, parent) # game variables self.my_number = random.randint(1, 10) self.count = 0 # create game directions lab = Label(self, text="I am thinking of a number 1 to 10...") lab.config(width=40, bg='blue', fg='white') labl = Label(self, text="Try to guess it in 3 tries!") labl.config(width=40, bg='blue', fg='white') lab.pack(side=TOP, fill=BOTH, pady=10) labl.pack(side=TOP, fill=BOTH, pady=5) # create results/hint window hint = Label(self, width=40, bg='orange', fg='white') hint.pack(side=TOP, fill=BOTH, pady=10) # create an entry for for your guess form = Frame(self) form.pack(side=TOP, fill=BOTH) ent_lab = Label(form, text="Your guess: ", width=10) ent_lab.pack(side=LEFT, padx=10) var = IntVar() ent = Entry(form, textvariable=var) ent.config(width=10, bg='lemon chiffon', fg='red') ent.pack(side=LEFT) # creates button to check the guess/ enter game loop but = Button(form, text="Check", width=10) but.config(command=(lambda: self.turn(var.get(), hint))) but.pack(side=RIGHT, fill=X, padx=10) # creates play again button new_game = Button(self, text='Play Again') new_game.config(command=(lambda: self.new_game(hint))) new_game.pack(side=TOP, fill=BOTH, expand=YES, padx=10, pady=5) # creates quit button quit = Quitter(self) quit.pack(side=TOP, fill=BOTH)
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) # 选中最后一个开始 Button(self, text='State', command=self.report).pack(fill=X) Quitter(self).pack(fill=X)
def __init__(self, parent=None, file=None): Frame.__init__(self, parent) self.pack() frm = Frame(self) frm.pack(fill=X) Button(frm, text='Save', command=self.onSave).pack(side=LEFT) Button(frm, text='Cut', command=self.onCut).pack(side=LEFT) Button(frm, text='Paste', command=self.onPaste).pack(side=LEFT) Button(frm, text='Find', command=self.onFind).pack(side=LEFT) Quitter(frm).pack(side=LEFT) self.st = ScrolledText(self, file=file) # attach, not subclass self.st.text.config(font=('courier', 9, 'normal'))
def __init__(self, parent=None): Frame.__init__(self, parent) self.pack() Label(self, text="Radio demos").pack(side=TOP) self.var = StringVar() for (key, value) in demos.items(): Radiobutton(self, text=key, command=self.onPress, variable=self.var, value=key).pack(anchor=NW) Button(self, text='State', command=self.report).pack(fill=X) Quitter(self).pack(fill=X)
def __init__(self, parent=None, **options): Frame.__init__(self, parent, **options) self.pack() Label(self, text='Radio demo').pack(side=TOP) self.var = StringVar() # variable shared between all radio buttons 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)
def __init__(self, master=None, cnf={}, **kw): super(Demo, self).__init__(master, cnf={}, **kw) self.pack() Label(master=self, text='Radio demos').pack(side=TOP) self.var = StringVar() for key in demos: Radiobutton(master=self, text=key, command=self.onPress, variable=self.var, value=key).pack(anchor=NW) self.var.set(key) Button(master=self, text='State', command=self.report).pack(fill=X) Quitter(master=self).pack(fill=X)
def __init__(self, parent=None, **options): Frame.__init__(self, parent, **options) self.pack() Label(self, text="Basic demos").pack() for (key, value) in demos.items( ): # es un diccionario => los botones apareceran no siempre en e mismo orden aleatorio Button(self, text=key, command=value).pack(side=TOP, fill=BOTH) # a la coleccion de botones anterior añade el boton quitter del ejemplo 8-7 Quitter(self).pack(side=TOP, fill=BOTH)
def __init__(self, parent=None): Frame.__init__(self, parent) # game variables self.count = 0 self.ent_answers = [] self.answers = {} self. questions = ["What is your name?", "What's your favorite animal?", "Name a place you want to go:", "What would you like to eat?", "Adjective please:", "Another adjective:", "Name a thing:", "Adjective please:", "Another adjective:", "Another object please:", "Yet another adjective:", "Last adjective, I promise:"] self.story = [] # create game directions ent_form = Frame(self).pack(side=LEFT) directions = Label(ent_form, text='Fill in the blanks!') directions.config(bg='firebrick', fg='white', height=2) directions.pack(side=TOP, pady=10, fill=BOTH) # creates the form for word entries entries = self.makeform(ent_form) # creates a button to start the story but = Button(ent_form, text='TELL ME A STORY!') but.config(command=(lambda: self.fetch(story_box))) but.pack(side=TOP, fill=BOTH, pady=10) # creates a storybox to display the story story_frm = Frame(self).pack(side=RIGHT) sbar = Scrollbar(story_frm) story_box = Text(story_frm, bd=2, height=20, width=80) story_box.config(wrap=WORD, relief=SUNKEN, fg='navy', bg='ivory') sbar.config(command=story_box.yview) story_box.config(yscrollcommand=sbar.set) sbar.pack(side=RIGHT, fill=Y) story_box.pack(side=TOP) btn_frm = Frame(story_frm).pack(side=TOP) Quitter(btn_frm).pack(side=LEFT) pg1_btn = Button(btn_frm, text='TELL ME MORE!') pg1_btn.config(command=(lambda: self.tell_story(story_box))) pg1_btn.pack(side=RIGHT)
def __init__(self, parent=None, **opt): Frame.__init__(self, parent, **opt) self.pack() self.ButtonTo = Button(self, text='Write toDir', command=self.toDirf) self.ButtonFrom = Button(self, text='Write fromDir', command=self.fromDirf) self.ButtonEnds = Button(self, text='White endswith', command=self.ends) self.ButtonStart = Button(self, text='Start', command=self.start) self.ButtonTo.pack(side=TOP) self.ButtonFrom.pack(side=TOP) self.ButtonEnds.pack(side=TOP) self.ButtonStart.pack(side=TOP) Quitter(self).pack(side=TOP)