diff --git a/chapter11_proxy/image_proxy.py b/chapter11_proxy/image_proxy.py new file mode 100644 index 0000000..db97269 --- /dev/null +++ b/chapter11_proxy/image_proxy.py @@ -0,0 +1,37 @@ +from tkinter import Tk, OptionMenu, mainloop, StringVar, Menu, Label +from PIL import ImageTk, Image + +class ImageProxy(Image): + def __init__(self, url): + super().__init__(self) + self.url = url + self._size = (800, 600) + + +def main(): + albums = {"Buddha Bar": r"http://images.amazon.com/images/P/B00009XBYK.01.LZZZZZZZ.jpg", + "Ima": r"http://images.amazon.com/images/P/B000005IRM.01.LZZZZZZZ.jpg", + "Karma": r"http://images.amazon.com/images/P/B000005DCB.01.LZZZZZZZ.gif", + "MCMXC a.D.": r"http://images.amazon.com/images/P/B000002URV.01.LZZZZZZZ.jpg", + "Northern Exposure": r"http://images.amazon.com/images/P/B000003SFN.01.LZZZZZZZ.jpg", + "Selected Ambient Works: Vol. 2": r"http://images.amazon.com/images/P/B000002MNZ.01.LZZZZZZZ.jpg" + } + album = "Selected Ambient Works: Vol. 2" + url = albums[album] + root = Tk() + menubar = Menu(root) + label = StringVar(root) + label.set(album) + menu = OptionMenu(root, label, *albums.keys()) + menubar.add_cascade(label="Album", menu=menu) + menu.pack() + img = r"C:\Users\Graham Knapp\OneDrive - Acernis AG\Pictures\Graham Knapp head WTTJ.jpg" + img = Image.open(img) + img = ImageTk.PhotoImage(img) + panel = Label(root, image=img) + panel.pack() + mainloop() + + +if __name__ == '__main__': + main() diff --git a/chapter11_proxy/readme.md b/chapter11_proxy/readme.md new file mode 100644 index 0000000..e324958 --- /dev/null +++ b/chapter11_proxy/readme.md @@ -0,0 +1,9 @@ +# Chapter 11: Proxy design pattern + +> **Proxy Pattern**: allows one object to stand in for another to control access. + +## Running the code + +```bash +python image_proxy.py +``` diff --git a/requirements.txt b/requirements.txt index 492e7e2..01cdd03 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -playsound == 1.2.2 \ No newline at end of file +playsound == 1.2.2 +pillow == 9.4.0 \ No newline at end of file pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy