Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Simple GUI

# img_viewer.py

import PySimpleGUI as sg
import os.path

# First the window layout in 2 columns

file_list_column = [
    [
        sg.Text("Image Folder"),
        sg.In(size=(25, 1), enable_events=True, key="-FOLDER-"),
        sg.FolderBrowse(),
    ],
    [
        sg.Listbox(
            values=[], enable_events=True, size=(40, 20), key="-FILE LIST-"
        )
    ],
]

# For now will only show the name of the file that was chosen
image_viewer_column = [
    [sg.Text("Choose an image from list on left:")],
    [sg.Text(size=(40, 1), key="-TOUT-")],
    [sg.Image(key="-IMAGE-")],
]

# ----- Full layout -----
layout = [
    [
        sg.Column(file_list_column),
        sg.VSeperator(),
        sg.Column(image_viewer_column),
    ]
]

window = sg.Window("Image Viewer", layout)

# Run the Event Loop
while True:
    event, values = window.read()
    if event == "Exit" or event == sg.WIN_CLOSED:
        break
    # Folder name was filled in, make a list of files in the folder
    if event == "-FOLDER-":
        folder = values["-FOLDER-"]
        try:
            # Get list of files in folder
            file_list = os.listdir(folder)
        except:
            file_list = []

        fnames = [
            f
            for f in file_list
            if os.path.isfile(os.path.join(folder, f))
            and f.lower().endswith((".png", ".gif"))
        ]
        window["-FILE LIST-"].update(fnames)
    elif event == "-FILE LIST-":  # A file was chosen from the listbox
        try:
            filename = os.path.join(
                values["-FOLDER-"], values["-FILE LIST-"][0]
            )
            window["-TOUT-"].update(filename)
            window["-IMAGE-"].update(filename=filename)

        except:
            pass

window.close()
Comment

simple gui

import PySimpleGUI as sg

sg.theme('BluePurple')

layout = [[sg.Text('Your typed chars appear here:'), sg.Text(size=(15,1), key='-OUTPUT-')],
          [sg.Input(key='-IN-')],
          [sg.Button('Show'), sg.Button('Exit')]]

window = sg.Window('Pattern 2B', layout)

while True:  # Event Loop
    event, values = window.read()
    print(event, values)
    if event == sg.WIN_CLOSED or event == 'Exit':
        break
    if event == 'Show':
        # Update the "output" text element to be the value of "input" element
        window['-OUTPUT-'].update(values['-IN-'])

window.close()
Comment

PREVIOUS NEXT
Code Example
Python :: loop regex 
Python :: write an empty block python 
Python :: how to Capture only the ICMP packet. using bpf 
Python :: how to make a yes or no question in python 
Python :: How to allow discord bot to respond to webhook. Python. Discord.py 
Python :: pyxl activate sheet 
Python :: load SQLite db into memory 
Python :: lxml etree fromstring find 
Python :: How to secure an endpoint for selected users with Flask-JWT-Extended 
Python :: plot bar 
Python :: python logical operators code in grepper 
Python :: Python (cpython 2.7.16) sample 
Python :: check if id is present in elasticsearch using python 
Python :: postgres fecth python 
Python :: ring Insert Items in list 
Python :: swagger django 
Python :: ring Trace Library 
Python :: How to Load Any HuggingFace Model in spaCy 
Python :: Uso de lambda 
Python :: convert python code to c++ online 
Python :: regression avec sklearn best 
Python :: foreign key on delete arguments 
Python :: fibonacci numbers in lamda python 
Python :: how to load images from folder in python 
Python :: mail.send_message flask not working, SSL == 465 
Python :: while my_input != "exit": 
Python :: python http handler iis 
Python :: TypeError: get() takes 1 positional argument but 2 were given 
Python :: how to take input a matrix using map in python 
Python :: using the return statement, defining a function, with input from the user. 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =