[Python编程(第4版)].(Programming.Python.4th.Edition).Mark.Lutz.文字版
Figure 8-35. demoAll_prg: independent programs Launching GUIs as programs other ways: multiprocessing If you backtrack to Chapte ...
from tkinter import * from multiprocessing import Process demoModules = ['demoDlg', 'demoRadio', 'demoCheck', 'demoScale'] def r ...
States button is gone this time, and we only get PortableLauncher messages in stdout as the demos start up in Example 8-34: C:\. ...
Coding for reusability A postscript: I coded the demo launcher bars deployed by the last four examples to demonstrate all the di ...
return [var.get() for var in self.vars] class Radiobar(Frame): def init(self, parent=None, picks=[], side=LEFT, anchor=W): Frame ...
Here’s the stdout text you get after pressing Peek—the results of these classes’ state methods: x11 [1, 0, 1, 1] [0] win [1, 0, ...
Figure 8-37. imgButton in action PhotoImage and its cousin, BitmapImage, essentially load graphics files and allow those graphic ...
Example 8-39. PP4E\Gui\Tour\imgCanvas2.py gifdir = "../gifs/" from sys import argv from tkinter import * filename = argv[1] if l ...
Run this script with other filenames to view other images (try this on your own): C:\...\PP4E\Gui\Tour> imgCanvas2.py ora-ppr ...
def draw(): name, photo = random.choice(images) lbl.config(text=name) pix.config(image=photo) root=Tk() lbl = Label(root, text=" ...
Figure 8-40. buttonpics in action Figure 8-41. buttonpics showing a taller photo Images | 489 ...
And finally, Figure 8-42 captures this script’s GUI displaying one of the wider GIFs, selected completely at random from the pho ...
self.lbl.config(text=name) self.pix.config(image=photo) if name == 'main': ButtonPicsDemo().mainloop() This version works the sa ...
with code of this form: from tkinter import * from PIL import ImageTk photoimg = ImageTk.PhotoImage(file=imgdir + "spam.jpg") Bu ...
Displaying Other Image Types with PIL In our earlier image examples, we attached widgets to buttons and canvases, but the standa ...
Figure 8-43. tkinter GIF display Example 8-42 works, but only for image types supported by the base tkinter toolkit. To display ...
win.mainloop() print(imgobj.width(), imgobj.height()) # show size in pixels on exit With PIL, our script is now able to display ...
import os, sys from tkinter import * from PIL.ImageTk import PhotoImage # <== required for JPEGs and others imgdir = 'images' ...
reuse the makeThumbs function here repeatedly in other examples. As usual, these are some of the primary benefits inherent in op ...
imgobj = PhotoImage(file=imgpath) Label(self, image=imgobj).pack() print(imgpath, imgobj.width(), imgobj.height()) # size in pix ...
«
22
23
24
25
26
27
28
29
30
31
»
Free download pdf