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

(yzsuai) #1

Inner().mainloop()


It can also be embedded in a container class—Example 19-19 attaches the simple cal-
culator’s widget package, along with extras, to a common parent.


Example 19-19. PP4E\Lang\Calculator\calc0emb.py


from tkinter import *
from calc0 import CalcGui # add parent, no master calls


class Outer:
def init(self, parent): # embed GUI
Label(parent, text='Calc Attachment').pack() # side=top
CalcGui(parent) # add calc frame
Button(parent, text='Quit', command=parent.quit).pack()


root = Tk()
Outer(root)
root.mainloop()


Figure 19-3 shows the result of running both of these scripts from different command
lines. Both have a distinct input field at the top. This works, but to see a more practical
application of such reuse techniques, we need to make the underlying calculator more
practical, too.


Figure 19-3. The calc0 script’s object attached and extended


1462 | Chapter 19: Text and Language

Free download pdf