Think Python How to Think Like a Computer Scientist
Download 1.04 Mb. Pdf ko'rish
|
thinkpython
- Bu sahifa navigatsiya:
- 19.11 Exercises Exercise 19.4
19.10
Glossary GUI: A graphical user interface. widget: One of the elements that makes up a GUI, including buttons, menus, text entry fields, etc. 194 Chapter 19. Case study: Tkinter option: A value that controls the appearance or function of a widget. keyword argument: An argument that indicates the parameter name as part of the function call. callback: A function associated with a widget that is called when the user performs an action. bound method: A method associated with a particular instance. event-driven programming: A style of programming in which the flow of execution is determined by user actions. event: A user action, like a mouse click or key press, that causes a GUI to respond. event loop: An infinite loop that waits for user actions and responds. item: A graphical element on a Canvas widget. bounding box: A rectangle that encloses a set of items, usually specified by two opposing corners. pack: To arrange and display the elements of a GUI. geometry manager: A system for packing widgets. binding: An association between a widget, an event, and an event handler. The event handler is called when the event occurs in the widget. 19.11 Exercises Exercise 19.4 For this exercise, you will write an image viewer. Here is a simple example: g = Gui() canvas = g.ca(width=300) photo = PhotoImage(file='danger.gif') canvas.image([0,0], image=photo) g.mainloop() PhotoImage reads a file and returns a PhotoImage object that Tkinter can display. Canvas.image puts the image on the canvas, centered on the given coordinates. You can also put images on labels, buttons, and some other widgets: g.la(image=photo) g.bu(image=photo) PhotoImage can only handle a few image formats, like GIF and PPM, but we can use the Python Imaging Library (PIL) to read other files. The name of the PIL module is Image, but Tkinter defines an object with the same name. To avoid the conflict, you can use import...as like this: import Image as PIL import ImageTk The first line imports Image and gives it the local name PIL. The second line imports ImageTk, which can translate a PIL image into a Tkinter PhotoImage. Here’s an example: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling