[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
In Chapter 8, we’ll meet two exceptions to this rule. Scripts must man- ually retain a reference to image objects because the un ...
we start using multiple top-level windows in Chapter 8, we’ll find that quit usually closes all windows, but its relative destro ...
This makes the button fill the whole window initially (its allocation is expanded, and it is stretched to fill that allocation). ...
In more complex displays, such a button will expand only if all of the widgets it is contained by are set to expand too. Here, t ...
C:\...\PP4E\Gui\Intro> python gui3.py Hello, I must be going... C:\...\PP4E\Gui\Intro> Normally, such messages would be di ...
Deferring Calls with Lambdas and Object References More typically, lambdas are used to provide an indirection layer that passes ...
Button(command=(lambda: handler('spam'))) # OK: wrap in a lambda to defer is always equivalent to the longer, and to some observ ...
For that matter, A could be moved out to the global scope too, to remove the need for lambda here entirely; we could register th ...
must be accessed again later, during event processing. Because tkinter calls the lambda function later with no arguments, all it ...
and replace the previously manual task of passing in enclosing scope values with de- faults altogether. Well, almost. There is a ...
def normal(): def action(): return spam # really, looked up when used spam = 'ni' return action act = normal() print(act()) # al ...
In terms of GUIs, this becomes significant most often when you generate callback han- dlers within loops and try to use enclosin ...
not change to a value you don’t expect after the nested function is created. You cannot generally reference enclosing scope loop ...
Later, we’ll see that class callback handler coding schemes provide a natural place to remember information for use on events—si ...
C:\...\PP4E\Gui\Intro> python gui3.py Hello, I must be going... C:\...\PP4E\Gui\Intro> python gui3b.py Hello lambda world ...
Scheduled event callbacks Finally, tkinter scripts can also register callback handlers to be run in special con- texts, such as ...
We’ll meet bind and all of the other tkinter event callback handler hooks again in more detail later in this book. First, though ...
Hello stdout world!... Hello stdout world!... The notion of attaching widgets to containers turns out to be at the core of layou ...
Similarly, displays that include scroll bars normally pack them before the items they scroll (e.g., text, lists) so that the scr ...
For instance, if you recode the gui4 child widget creation logic like this: Button(win, text='Hello', command=greeting).pack(sid ...
«
17
18
19
20
21
22
23
24
25
26
»
Free download pdf