The last piece of code to cover are these lines: while True: Any Element you need to access later should also be given a name, which is the key argument. You disable the Input Element to make it read-only and prevent typing into it - each keypress would be an individual Event, and your loop is not prepared for that. To enable events for an Element, you set the enable_events argument to True - this will submit an Event whenever the Element changes. FileBrowse - A button that opens a file browser dialog. The reason they are lined up horizontally is because they are in a nested list. These three widgets are lined up horizontally in the form from left-to-right. Then you want to add three more widgets underneath it. In this case, you are telling it that you want to create an Image widget at the top of your Window. PySimpleGUI uses Python lists to lay out the user interface. These 11 lines of code define how your Elements are laid out. Window = sg.Window("Image Viewer", elements) Now you're ready to learn about the main() function: def main(): You import PySimpleGUI and the modules you need from PIL, and set file_types to the file selection choices for the Browse button in the form, which will default to JPEG. Let's break it down into a couple of smaller pieces: # image_viewer.py If event = "Exit" or event = sg.WIN_CLOSED: Window = sg.Window("Image Viewer", layout) Then add this code to the file: # image_viewer.py To see how, create a new file and name it image_viewer.py. PySimpleGUI lets you create a simple image viewer in less than 50 lines. Now that you have your dependencies installed, you can create a brand new application! Creating an Image Viewer #Python simpleimage install#You will also need Pillow because Tkinter only supports GIF and PGM/PPM image types.įortunately, you can install both of these packages easily with pip: python3 -m pip install PySimpleGUI Pillow You need to install PySimpleGUI as it is not included with Python. You will be using the regular version of PySimpleGUI, which wraps Tkinter, rather than its wxPython or PyQt variants. #Python simpleimage how to#In this tutorial, you will learn how to use PySimpleGUI to create a simple Image Viewer. PySimpleGUI makes creating applications easy.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |