-
Notifications
You must be signed in to change notification settings - Fork 0
/
PySimple.py
102 lines (85 loc) · 2.8 KB
/
PySimple.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#make sure to import rpy2, pysimpleGUI, pillow
import PySimpleGUI as sg
import os.path
from tkinter import *
sg.theme('BlueMono')
# This creates the widgets for the left column
file_list_column = [
[
#creating your image browsing button
sg.Text("Image Folder"),
sg.In(size=(25, 1), enable_events=True, key="-FOLDER-"),
sg.FolderBrowse(),
],
[
#dropdown list to see the image files to choose from
sg.Listbox(
values=[], enable_events=True, size=(40, 20), key="-FILE LIST-"
)
],
[sg.Button('Click counter')],
]
# This creats the text that is displayed above the image
image_viewer_column = [
[sg.Text("Choose an image from list on left:")],
[sg.Text(size=(100, 1), key="-TOUT-")],
[sg.Image(key="-IMAGE-")],
]
# Segmenting the program into different sections
layout = [
[
sg.Column(file_list_column),
sg.VSeperator(),
sg.Column(image_viewer_column),
]
]
# Creating the window, naming it, and adding our layout to the window
window = sg.Window("Image Viewer", layout).Finalize()
window.Maximize()
# Event loop
while True:
event, values = window.read()
if event == "Exit" or event == sg.WIN_CLOSED: #if they wanna exit this lets them do that
break
if event == "Click counter":
class clickCount:
def clicks(self, event):
# clicks = 0
global count
count += 1
return count
def main(self, h, w):
root = Tk()
root.minsize(h, w)
root.attributes('-alpha', 0.25)
root.bind("<Button-1>", self.clicks)
root.mainloop()
return count
count = 0
height, width = 700, 500 # sample window/image size
total = clickCount()
print(total.main(height, width))
# If the folder button function is called, 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", ".jpg")) #this is the file types that our progam will accept
]
window["-FILE LIST-"].update(fnames) #This will be updating the file list
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