[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版

(yzsuai) #1

build message window


Stat = PopupWindow('PP4E demo info')
Stat.protocol('WM_DELETE_WINDOW', lambda:0) # ignore wm delete


Info = Label(Stat, text = 'Select demo',
font=('courier', 20, 'italic'), padx=12, pady=12, bg='lightblue')
Info.pack(expand=YES, fill=BOTH)


################################################################################


add launcher buttons with callback objects


################################################################################


from PP4E.Gui.TextEditor.textEditor import TextEditorMainPopup


demo launcher class


class Launcher(launchmodes.PortableLauncher): # use wrapped launcher class
def announce(self, text): # customize to set GUI label
Info.config(text=text)


def viewer(sources):
for filename in sources:
TextEditorMainPopup(Root, filename, # as pop up in this process
loadEncode='utf-8') # else PyEdit may ask each!


def demoButton(name, what, doit, code):
"""
add buttons that runs doit command-line, and open all files in code;
doit button retains state in an object, code in an enclosing scope;
"""
rowfrm = Frame(Root)
rowfrm.pack(side=TOP, expand=YES, fill=BOTH)


b = Button(rowfrm, bg='navy', fg='white', relief=RIDGE, border=4)
b.config(text=name, width=20, command=Launcher(what, doit))
b.pack(side=LEFT, expand=YES, fill=BOTH)


b = Button(rowfrm, bg='beige', fg='navy')
b.config(text='code', command=(lambda: viewer(code)))
b.pack(side=LEFT, fill=BOTH)


################################################################################


tkinter GUI demos - some use network connections


################################################################################


demoButton(name='PyEdit',
what='Text file editor', # edit myself
doit='Gui/TextEditor/textEditor.py PyDemos.pyw', # assume in cwd
code=['launchmodes.py',
'Tools/find.py',
'Gui/Tour/scrolledlist.py', # show in PyEdit viewer
'Gui/ShellGui/formrows.py', # last = top of stacking
'Gui/Tools/guimaker.py',
'Gui/TextEditor/textConfig.py',
'Gui/TextEditor/textEditor.py'])


666 | Chapter 10: GUI Coding Techniques

Free download pdf