Adjusted wraplength, Updated demo program that displays PNG files

This commit is contained in:
MikeTheWatchGuy 2018-08-22 17:14:58 -04:00
parent 6547a1b689
commit b1829438a9
2 changed files with 14 additions and 13 deletions

View File

@ -3,8 +3,6 @@ import os
# Simple Image Browser based on PySimpleGUI
# sg.ChangeLookAndFeel('GreenTan')
# Get the folder containing the images from the user
rc, folder = sg.GetPathBox('Image Browser', 'Image folder to open', default_path='A:/TEMP/PDFs')
if rc is False or folder is '':
@ -18,39 +16,42 @@ if len(png_files) == 0:
sg.MsgBox('No PNG images in folder')
exit(0)
# create the form
# create the form that also returns keyboard events
form = sg.FlexForm('Image Browser', return_keyboard_events=True)
# make these 2 elements outside the layout because want to "update" them later
# initialize to the first PNG file in the list
image_elem = sg.Image(filename=png_files[0])
text_elem = sg.Text(png_files[0], size=(80,3))
filename_display_elem = sg.Text(png_files[0], size=(80, 3))
file_num_display_elem = sg.Text('File 1 of {}'.format(len(png_files)), size=(10,1))
# define layout, show and read the form
layout = [[text_elem],
layout = [[filename_display_elem],
[image_elem],
[sg.ReadFormButton('Next', size=(8,2)), sg.ReadFormButton('Prev', size=(8,2))]]
[sg.ReadFormButton('Next', size=(8,2)), sg.ReadFormButton('Prev', size=(8,2)), file_num_display_elem]]
form.LayoutAndRead(layout)
form.LayoutAndRead(layout) # Shows form on screen
# loop reading the user input and display each image and the filename
# loop reading the user input and displaying image, filename
i=0
while True:
f = png_files[i]
# update window with new image
image_elem.Update(filename=f)
# update window with filename
text_elem.Update(f)
filename_display_elem.Update(f)
# update page display
file_num_display_elem.Update('File {} of {}'.format(i+1, len(png_files)))
# read the form
button, values = form.Read()
# perform button operations
# perform button and keyboard operations
if button is None:
break
elif button in ('Next', 'MouseWheel:Down', 'Down:40', 'Next:34') and i < len(png_files):
i += 1
elif button in ('Prev', 'MouseWheel:Up', 'Up:38', 'Prior:33') and i > 0:
i -= 1
# else:
# print(button)

View File

@ -1458,7 +1458,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
# tktext_label = tk.Label(tk_row_frame,anchor=tk.NW, text=display_text, width=width, height=height, justify=tk.LEFT, bd=border_depth)
# Set wrap-length for text (in PIXELS) == PAIN IN THE ASS
wraplen = tktext_label.winfo_reqwidth() # width of widget in Pixels
tktext_label.configure(anchor=anchor, font=font, wraplen=0) # set wrap to width of widget
tktext_label.configure(anchor=anchor, font=font, wraplen=wraplen+40) # set wrap to width of widget
if element.BackgroundColor is not None:
tktext_label.configure(background=element.BackgroundColor)
if element.TextColor != COLOR_SYSTEM_DEFAULT and element.TextColor is not None: