12.07.2015 Views

Is Python a

Is Python a

Is Python a

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

win = Tk( )L = Label(win, text='Spam',font=('arial', fontsize, 'italic'), fg='yellow', bg='navy',relief=RAISED)L.pack(side=TOP, expand=YES, fill=BOTH)Button(win, text='press', command=(lambda: reply('red'))).pack(side=BOTTOM,fill=X)Button(win, text='timer', command=timer).pack(side=BOTTOM, fill=X)Button(win, text='grow' , command=grow).pack(side=BOTTOM, fill=X)win.mainloop( )# Similar to prior, but use classes so each window has own state informationfrom Tkinter import *import randomclass MyGui:"""A GUI with buttons that change color and make the label grow"""colors = ['blue', 'green', 'orange', 'red', 'brown', 'yellow']def _ _init_ _(self, parent, title='popup'):parent.title(title)self.growing = Falseself.fontsize = 10self.lab = Label(parent, text='Gui1', fg='white', bg='navy')self.lab.pack(expand=YES, fill=BOTH)Button(parent, text='Spam', command=self.reply).pack(side=LEFT)Button(parent, text='Grow', command=self.grow).pack(side=LEFT)Button(parent, text='Stop', command=self.stop).pack(side=LEFT)def reply(self):"change the button's color at random on Spam presses"self.fontsize += 5color = random.choice(self.colors)self.lab.config(bg=color,font=('courier', self.fontsize, 'bold italic'))def grow(self):"start making the label grow on Grow presses"self.growing = Trueself.grower( )def grower(self):if self.growing:self.fontsize += 5self.lab.config(font=('courier', self.fontsize, 'bold'))self.lab.after(500, self.grower)def stop(self):"stop the button growing on Stop presses"self.growing = FalsePart VII, Exceptions and Tools | 677

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!