commit
c8c1e3a7f7
|
@ -0,0 +1,65 @@
|
||||||
|
import PySimpleGUI as sg
|
||||||
|
|
||||||
|
|
||||||
|
def Everything():
|
||||||
|
|
||||||
|
with sg.FlexForm('Everything bagel', auto_size_text=True, default_element_size=(40, 1)) as form:
|
||||||
|
layout = [
|
||||||
|
[sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25))],
|
||||||
|
[sg.Text('Here is some text.... and a place to enter text')],
|
||||||
|
[sg.InputText()],
|
||||||
|
[sg.Checkbox('My first checkbox!'), sg.Checkbox('My second checkbox!', default=True)],
|
||||||
|
[sg.Radio('My first Radio! ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
|
||||||
|
[sg.Multiline(default_text='This is the default Text should you decide not to type anything',size=(35,3)),
|
||||||
|
sg.Multiline(default_text='A second multi-line',size=(35,3))],
|
||||||
|
[sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 3)),
|
||||||
|
sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
|
||||||
|
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3', 'Listbox 4'), size=(30, 3)),
|
||||||
|
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25),
|
||||||
|
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
|
||||||
|
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
|
||||||
|
sg.Spin(values=('Spin Box 1', '2','3'), initial_value='Spin Box 1')],
|
||||||
|
[sg.Text('_' * 80)],
|
||||||
|
[sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'), sg.InputText('Default Folder'), sg.FolderBrowse()],
|
||||||
|
[sg.Submit(), sg.Cancel()] ]
|
||||||
|
|
||||||
|
button, values = form.LayoutAndRead(layout)
|
||||||
|
|
||||||
|
sg.MsgBox('Title', 'The results of the form.', 'The button clicked was "{}"'.format(button), 'The values are', values)
|
||||||
|
|
||||||
|
import PySimpleGUI as sg
|
||||||
|
|
||||||
|
sg.ChangeLookAndFeel('GreenTan')
|
||||||
|
|
||||||
|
form = sg.FlexForm('Everything bagel', default_element_size=(40, 1))
|
||||||
|
|
||||||
|
column1 = [[sg.Text('Column 1', background_color='#d3dfda', justification='center', size=(10,1))],
|
||||||
|
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
|
||||||
|
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
|
||||||
|
[sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]
|
||||||
|
layout = [
|
||||||
|
[sg.Text('All graphic widgets in one form!', size=(30, 1), font=("Helvetica", 25))],
|
||||||
|
[sg.Text('Here is some text.... and a place to enter text')],
|
||||||
|
[sg.InputText('This is my text')],
|
||||||
|
[sg.Checkbox('My first checkbox!'), sg.Checkbox('My second checkbox!', default=True)],
|
||||||
|
[sg.Radio('My first Radio! ', "RADIO1", default=True), sg.Radio('My second Radio!', "RADIO1")],
|
||||||
|
[sg.Multiline(default_text='This is the default Text should you decide not to type anything', size=(35, 3)),
|
||||||
|
sg.Multiline(default_text='A second multi-line', size=(35, 3))],
|
||||||
|
[sg.InputCombo(('Combobox 1', 'Combobox 2'), size=(20, 3)),
|
||||||
|
sg.Slider(range=(1, 100), orientation='h', size=(34, 20), default_value=85)],
|
||||||
|
[sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(30, 3)),
|
||||||
|
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=25),
|
||||||
|
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=75),
|
||||||
|
sg.Slider(range=(1, 100), orientation='v', size=(5, 20), default_value=10),
|
||||||
|
sg.Column(column1, background_color='#d3dfda')],
|
||||||
|
[sg.Text('_' * 80)],
|
||||||
|
[sg.Text('Choose A Folder', size=(35, 1))],
|
||||||
|
[sg.Text('Your Folder', size=(15, 1), auto_size_text=False, justification='right'),
|
||||||
|
sg.InputText('Default Folder'), sg.FolderBrowse()],
|
||||||
|
[sg.Submit(), sg.Cancel()]
|
||||||
|
]
|
||||||
|
|
||||||
|
button, values = form.LayoutAndRead(layout)
|
||||||
|
sg.MsgBox(button, values)
|
||||||
|
|
||||||
|
# Everything_NoContextManager()
|
150
PySimpleGUI.py
150
PySimpleGUI.py
|
@ -100,6 +100,14 @@ class MyWindows():
|
||||||
self.NumOpenWindows = 0
|
self.NumOpenWindows = 0
|
||||||
self.user_defined_icon = None
|
self.user_defined_icon = None
|
||||||
|
|
||||||
|
def Decrement(self):
|
||||||
|
self.NumOpenWindows -= 1 * (self.NumOpenWindows != 0) # decrement if not 0
|
||||||
|
print('---- DECREMENTING Num Open Windows = {} ---'.format(self.NumOpenWindows))
|
||||||
|
|
||||||
|
def Increment(self):
|
||||||
|
self.NumOpenWindows += 1
|
||||||
|
print('++++ INCREMENTING Num Open Windows = {} ++++'.format(self.NumOpenWindows))
|
||||||
|
|
||||||
_my_windows = MyWindows() # terrible hack using globals... means need a class for collecing windows
|
_my_windows = MyWindows() # terrible hack using globals... means need a class for collecing windows
|
||||||
|
|
||||||
# ====================================================================== #
|
# ====================================================================== #
|
||||||
|
@ -116,6 +124,7 @@ def RGB(red,green,blue): return '#%02x%02x%02x' % (red,green,blue)
|
||||||
# class ButtonType(Enum):
|
# class ButtonType(Enum):
|
||||||
BUTTON_TYPE_BROWSE_FOLDER = 1
|
BUTTON_TYPE_BROWSE_FOLDER = 1
|
||||||
BUTTON_TYPE_BROWSE_FILE = 2
|
BUTTON_TYPE_BROWSE_FILE = 2
|
||||||
|
BUTTON_TYPE_SAVEAS_FILE = 3
|
||||||
BUTTON_TYPE_CLOSES_WIN = 5
|
BUTTON_TYPE_CLOSES_WIN = 5
|
||||||
BUTTON_TYPE_READ_FORM = 7
|
BUTTON_TYPE_READ_FORM = 7
|
||||||
BUTTON_TYPE_REALTIME = 9
|
BUTTON_TYPE_REALTIME = 9
|
||||||
|
@ -261,7 +270,7 @@ class InputCombo(Element):
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------- #
|
||||||
# Combo #
|
# Listbox #
|
||||||
# ---------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------- #
|
||||||
class Listbox(Element):
|
class Listbox(Element):
|
||||||
|
|
||||||
|
@ -514,16 +523,18 @@ class TKProgressBar():
|
||||||
# ---------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------- #
|
||||||
class TKOutput(tk.Frame):
|
class TKOutput(tk.Frame):
|
||||||
def __init__(self, parent, width, height, bd, background_color=None, text_color=None):
|
def __init__(self, parent, width, height, bd, background_color=None, text_color=None):
|
||||||
tk.Frame.__init__(self, parent)
|
frame = tk.Frame(parent, width=width, height=height)
|
||||||
self.output = tk.Text(parent, width=width, height=height, bd=bd)
|
tk.Frame.__init__(self, frame)
|
||||||
|
self.output = tk.Text(frame, width=width, height=height, bd=bd)
|
||||||
if background_color and background_color != COLOR_SYSTEM_DEFAULT:
|
if background_color and background_color != COLOR_SYSTEM_DEFAULT:
|
||||||
self.output.configure(background=background_color)
|
self.output.configure(background=background_color)
|
||||||
if text_color and text_color != COLOR_SYSTEM_DEFAULT:
|
if text_color and text_color != COLOR_SYSTEM_DEFAULT:
|
||||||
self.output.configure(fg=text_color)
|
self.output.configure(fg=text_color)
|
||||||
self.vsb = tk.Scrollbar(parent, orient="vertical", command=self.output.yview)
|
self.vsb = tk.Scrollbar(frame, orient="vertical", command=self.output.yview)
|
||||||
self.output.configure(yscrollcommand=self.vsb.set)
|
self.output.configure(yscrollcommand=self.vsb.set)
|
||||||
self.output.pack(side="left", fill="both", expand=True)
|
self.output.pack(side="left", fill="both")
|
||||||
self.vsb.pack(side="left", fill="y")
|
self.vsb.pack(side="left", fill="y")
|
||||||
|
frame.pack(side="left")
|
||||||
self.previous_stdout = sys.stdout
|
self.previous_stdout = sys.stdout
|
||||||
self.previous_stderr = sys.stderr
|
self.previous_stderr = sys.stderr
|
||||||
|
|
||||||
|
@ -650,6 +661,9 @@ class Button(Element):
|
||||||
elif self.BType == BUTTON_TYPE_BROWSE_FILE:
|
elif self.BType == BUTTON_TYPE_BROWSE_FILE:
|
||||||
file_name = tk.filedialog.askopenfilename(filetypes=filetypes) # show the 'get file' dialog box
|
file_name = tk.filedialog.askopenfilename(filetypes=filetypes) # show the 'get file' dialog box
|
||||||
strvar.set(file_name)
|
strvar.set(file_name)
|
||||||
|
elif self.BType == BUTTON_TYPE_SAVEAS_FILE:
|
||||||
|
file_name = tk.filedialog.asksaveasfilename(filetypes=filetypes) # show the 'get file' dialog box
|
||||||
|
strvar.set(file_name)
|
||||||
elif self.BType == BUTTON_TYPE_CLOSES_WIN: # this is a return type button so GET RESULTS and destroy window
|
elif self.BType == BUTTON_TYPE_CLOSES_WIN: # this is a return type button so GET RESULTS and destroy window
|
||||||
# first, get the results table built
|
# first, get the results table built
|
||||||
# modify the Results table in the parent FlexForm object
|
# modify the Results table in the parent FlexForm object
|
||||||
|
@ -664,7 +678,7 @@ class Button(Element):
|
||||||
self.ParentForm.TKroot.quit()
|
self.ParentForm.TKroot.quit()
|
||||||
if self.ParentForm.NonBlocking:
|
if self.ParentForm.NonBlocking:
|
||||||
self.ParentForm.TKroot.destroy()
|
self.ParentForm.TKroot.destroy()
|
||||||
# _my_windows.NumOpenWindows -= 1 * (_my_windows.NumOpenWindows != 0) # decrement if not 0
|
_my_windows.Decrement()
|
||||||
elif self.BType == BUTTON_TYPE_READ_FORM: # LEAVE THE WINDOW OPEN!! DO NOT CLOSE
|
elif self.BType == BUTTON_TYPE_READ_FORM: # LEAVE THE WINDOW OPEN!! DO NOT CLOSE
|
||||||
# first, get the results table built
|
# first, get the results table built
|
||||||
# modify the Results table in the parent FlexForm object
|
# modify the Results table in the parent FlexForm object
|
||||||
|
@ -718,7 +732,7 @@ class ProgressBar(Element):
|
||||||
try:
|
try:
|
||||||
self.ParentForm.TKroot.update()
|
self.ParentForm.TKroot.update()
|
||||||
except:
|
except:
|
||||||
# _my_windows.NumOpenWindows -= 1 * (_my_windows.NumOpenWindows != 0) # decrement if not 0
|
# _my_windows.Decrement()
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -733,7 +747,7 @@ class ProgressBar(Element):
|
||||||
# Image #
|
# Image #
|
||||||
# ---------------------------------------------------------------------- #
|
# ---------------------------------------------------------------------- #
|
||||||
class Image(Element):
|
class Image(Element):
|
||||||
def __init__(self, filename, scale=(None, None), size=(None, None)):
|
def __init__(self, filename=None, data=None,scale=(None, None), size=(None, None)):
|
||||||
'''
|
'''
|
||||||
Image Element
|
Image Element
|
||||||
:param filename:
|
:param filename:
|
||||||
|
@ -741,9 +755,23 @@ class Image(Element):
|
||||||
:param size: Size of field in characters
|
:param size: Size of field in characters
|
||||||
'''
|
'''
|
||||||
self.Filename = filename
|
self.Filename = filename
|
||||||
|
self.Data = data
|
||||||
|
self.tktext_label = None
|
||||||
|
|
||||||
|
if data is None and filename is None:
|
||||||
|
print('* Warning... no image specified in Image Element! *')
|
||||||
super().__init__(ELEM_TYPE_IMAGE, scale=scale, size=size)
|
super().__init__(ELEM_TYPE_IMAGE, scale=scale, size=size)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def Update(self, filename=None, data=None):
|
||||||
|
if filename is not None:
|
||||||
|
image = tk.PhotoImage(file=filename)
|
||||||
|
elif data is not None:
|
||||||
|
image = tk.PhotoImage(data=data)
|
||||||
|
else: return
|
||||||
|
self.tktext_label.configure(image=image)
|
||||||
|
self.tktext_label.image = image
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
super().__del__()
|
super().__del__()
|
||||||
|
|
||||||
|
@ -821,7 +849,7 @@ class Column(Element):
|
||||||
for element in row:
|
for element in row:
|
||||||
element.__del__()
|
element.__del__()
|
||||||
try:
|
try:
|
||||||
del(self.TKroot)
|
del(self.TKFrame)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
super().__del__()
|
super().__del__()
|
||||||
|
@ -968,7 +996,7 @@ class FlexForm:
|
||||||
self.TKroot.mainloop()
|
self.TKroot.mainloop()
|
||||||
if self.RootNeedsDestroying:
|
if self.RootNeedsDestroying:
|
||||||
self.TKroot.destroy()
|
self.TKroot.destroy()
|
||||||
_my_windows.NumOpenWindows -= 1 * (_my_windows.NumOpenWindows != 0) # decrement if not 0
|
_my_windows.Decrement()
|
||||||
return BuildResults(self, False, self)
|
return BuildResults(self, False, self)
|
||||||
|
|
||||||
def ReadNonBlocking(self, Message=''):
|
def ReadNonBlocking(self, Message=''):
|
||||||
|
@ -982,7 +1010,7 @@ class FlexForm:
|
||||||
rc = self.TKroot.update()
|
rc = self.TKroot.update()
|
||||||
except:
|
except:
|
||||||
self.TKrootDestroyed = True
|
self.TKrootDestroyed = True
|
||||||
_my_windows.NumOpenWindows -= 1 * (_my_windows.NumOpenWindows != 0) # decrement if not 0
|
_my_windows.Decrement()
|
||||||
return BuildResults(self, False, self)
|
return BuildResults(self, False, self)
|
||||||
|
|
||||||
|
|
||||||
|
@ -999,10 +1027,12 @@ class FlexForm:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def CloseNonBlockingForm(self):
|
def CloseNonBlockingForm(self):
|
||||||
|
if self.TKrootDestroyed:
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
self.TKroot.destroy()
|
self.TKroot.destroy()
|
||||||
|
_my_windows.Decrement()
|
||||||
except: pass
|
except: pass
|
||||||
_my_windows.NumOpenWindows -= 1 * (_my_windows.NumOpenWindows != 0) # decrement if not 0
|
|
||||||
|
|
||||||
def OnClosingCallback(self):
|
def OnClosingCallback(self):
|
||||||
return
|
return
|
||||||
|
@ -1049,7 +1079,7 @@ class UberForm():
|
||||||
if not self.TKrootDestroyed:
|
if not self.TKrootDestroyed:
|
||||||
self.TKrootDestroyed = True
|
self.TKrootDestroyed = True
|
||||||
self.TKroot.destroy()
|
self.TKroot.destroy()
|
||||||
_my_windows.NumOpenWindows -= 1 * (_my_windows.NumOpenWindows != 0) # decrement if not 0
|
_my_windows.Decrement()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
return
|
return
|
||||||
|
@ -1082,24 +1112,36 @@ def T(display_text, scale=(None, None), size=(None, None), auto_size_text=None,
|
||||||
return Text(display_text, scale=scale, size=size, auto_size_text=auto_size_text, font=font, text_color=text_color, justification=justification)
|
return Text(display_text, scale=scale, size=size, auto_size_text=auto_size_text, font=font, text_color=text_color, justification=justification)
|
||||||
|
|
||||||
# ------------------------- FOLDER BROWSE Element lazy function ------------------------- #
|
# ------------------------- FOLDER BROWSE Element lazy function ------------------------- #
|
||||||
def FolderBrowse(target=(ThisRow, -1), button_text='Browse', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None):
|
def FolderBrowse(target=(ThisRow, -1), button_text='Browse', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None):
|
||||||
return Button(BUTTON_TYPE_BROWSE_FOLDER, target=target, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color)
|
return Button(BUTTON_TYPE_BROWSE_FOLDER, target=target, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color)
|
||||||
|
|
||||||
# ------------------------- FILE BROWSE Element lazy function ------------------------- #
|
# ------------------------- FILE BROWSE Element lazy function ------------------------- #
|
||||||
def FileBrowse(target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), button_text='Browse', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None):
|
def FileBrowse(target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), button_text='Browse', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None):
|
||||||
return Button(BUTTON_TYPE_BROWSE_FILE, target, button_text=button_text, file_types=file_types, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color)
|
return Button(BUTTON_TYPE_BROWSE_FILE, target, button_text=button_text, file_types=file_types, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font)
|
||||||
|
|
||||||
|
# ------------------------- FILE BROWSE Element lazy function ------------------------- #
|
||||||
|
def FileSaveAs(target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), button_text='Save As...', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None):
|
||||||
|
return Button(BUTTON_TYPE_SAVEAS_FILE, target, button_text=button_text, file_types=file_types, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font)
|
||||||
|
|
||||||
|
# ------------------------- SAVE AS Element lazy function ------------------------- #
|
||||||
|
def SaveAs(target=(ThisRow, -1), file_types=(("ALL Files", "*.*"),), button_text='Save As...', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None):
|
||||||
|
return Button(BUTTON_TYPE_BROWSE_FILE, target, button_text=button_text, file_types=file_types, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font)
|
||||||
|
|
||||||
|
# ------------------------- SAVE BUTTON Element lazy function ------------------------- #
|
||||||
|
def Save(button_text='Save', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True,font=None, focus=False):
|
||||||
|
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus)
|
||||||
|
|
||||||
# ------------------------- SUBMIT BUTTON Element lazy function ------------------------- #
|
# ------------------------- SUBMIT BUTTON Element lazy function ------------------------- #
|
||||||
def Submit(button_text='Submit', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True, focus=False):
|
def Submit(button_text='Submit', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True,font=None, focus=False):
|
||||||
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, bind_return_key=bind_return_key, focus=focus)
|
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus)
|
||||||
|
|
||||||
# ------------------------- OK BUTTON Element lazy function ------------------------- #
|
# ------------------------- OK BUTTON Element lazy function ------------------------- #
|
||||||
def OK(button_text='OK', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True, focus=False):
|
def OK(button_text='OK', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True, font=None,focus=False):
|
||||||
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, bind_return_key=bind_return_key, focus=focus)
|
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color,font=font, bind_return_key=bind_return_key, focus=focus)
|
||||||
|
|
||||||
# ------------------------- YES BUTTON Element lazy function ------------------------- #
|
# ------------------------- YES BUTTON Element lazy function ------------------------- #
|
||||||
def Ok(button_text='Ok', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True, focus=False):
|
def Ok(button_text='Ok', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True, font=None,focus=False):
|
||||||
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, bind_return_key=bind_return_key, focus=focus)
|
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus)
|
||||||
|
|
||||||
# ------------------------- CANCEL BUTTON Element lazy function ------------------------- #
|
# ------------------------- CANCEL BUTTON Element lazy function ------------------------- #
|
||||||
def Cancel(button_text='Cancel', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False):
|
def Cancel(button_text='Cancel', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False):
|
||||||
|
@ -1109,13 +1151,17 @@ def Cancel(button_text='Cancel', scale=(None, None), size=(None, None), auto_siz
|
||||||
def Quit(button_text='Quit', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False):
|
def Quit(button_text='Quit', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False):
|
||||||
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus)
|
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus)
|
||||||
|
|
||||||
|
# ------------------------- Exit BUTTON Element lazy function ------------------------- #
|
||||||
|
def Exit(button_text='Exit', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, font=None, bind_return_key=False, focus=False):
|
||||||
|
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus)
|
||||||
|
|
||||||
# ------------------------- YES BUTTON Element lazy function ------------------------- #
|
# ------------------------- YES BUTTON Element lazy function ------------------------- #
|
||||||
def Yes(button_text='Yes', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=True, focus=False):
|
def Yes(button_text='Yes', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None,font=None, bind_return_key=True, focus=False):
|
||||||
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, bind_return_key=bind_return_key, focus=focus)
|
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus)
|
||||||
|
|
||||||
# ------------------------- NO BUTTON Element lazy function ------------------------- #
|
# ------------------------- NO BUTTON Element lazy function ------------------------- #
|
||||||
def No(button_text='No', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None, bind_return_key=False, focus=False):
|
def No(button_text='No', scale=(None, None), size=(None, None), auto_size_button=None, button_color=None,font=None, bind_return_key=False, focus=False):
|
||||||
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, bind_return_key=bind_return_key, focus=focus)
|
return Button(BUTTON_TYPE_CLOSES_WIN, button_text=button_text, scale=scale, size=size, auto_size_button=auto_size_button, button_color=button_color, font=font, bind_return_key=bind_return_key, focus=focus)
|
||||||
|
|
||||||
# ------------------------- GENERIC BUTTON Element lazy function ------------------------- #
|
# ------------------------- GENERIC BUTTON Element lazy function ------------------------- #
|
||||||
# this is the only button that REQUIRES button text field
|
# this is the only button that REQUIRES button text field
|
||||||
|
@ -1378,6 +1424,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
element.TKButton = tkbutton # not used yet but save the TK button in case
|
element.TKButton = tkbutton # not used yet but save the TK button in case
|
||||||
wraplen = tkbutton.winfo_reqwidth() # width of widget in Pixels
|
wraplen = tkbutton.winfo_reqwidth() # width of widget in Pixels
|
||||||
if element.ImageFilename: # if button has an image on it
|
if element.ImageFilename: # if button has an image on it
|
||||||
|
tkbutton.config(highlightthickness=0)
|
||||||
photo = tk.PhotoImage(file=element.ImageFilename)
|
photo = tk.PhotoImage(file=element.ImageFilename)
|
||||||
if element.ImageSize != (None, None):
|
if element.ImageSize != (None, None):
|
||||||
width, height = element.ImageSize
|
width, height = element.ImageSize
|
||||||
|
@ -1387,7 +1434,10 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
width, height = photo.width(), photo.height()
|
width, height = photo.width(), photo.height()
|
||||||
tkbutton.config(image=photo, width=width, height=height)
|
tkbutton.config(image=photo, width=width, height=height)
|
||||||
tkbutton.image = photo
|
tkbutton.image = photo
|
||||||
tkbutton.configure(wraplength=wraplen+10, font=font) # set wrap to width of widget
|
if width != 0:
|
||||||
|
tkbutton.configure(wraplength=wraplen+10, font=font) # set wrap to width of widget
|
||||||
|
else:
|
||||||
|
tkbutton.configure(font=font) # only set the font, not wraplength
|
||||||
tkbutton.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
|
tkbutton.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1])
|
||||||
if element.Focus is True or (toplevel_form.UseDefaultFocus and not focus_set):
|
if element.Focus is True or (toplevel_form.UseDefaultFocus and not focus_set):
|
||||||
focus_set = True
|
focus_set = True
|
||||||
|
@ -1452,9 +1502,9 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
max_line_len = max([len(str(l)) for l in element.Values])
|
max_line_len = max([len(str(l)) for l in element.Values])
|
||||||
if auto_size_text is False: width=element_size[0]
|
if auto_size_text is False: width=element_size[0]
|
||||||
else: width = max_line_len
|
else: width = max_line_len
|
||||||
|
listbox_frame = tk.Frame(tk_row_frame)
|
||||||
element.TKStringVar = tk.StringVar()
|
element.TKStringVar = tk.StringVar()
|
||||||
element.TKListbox= tk.Listbox(tk_row_frame, height=element_size[1], width=width, selectmode=element.SelectMode, font=font)
|
element.TKListbox= tk.Listbox(listbox_frame, height=element_size[1], width=width, selectmode=element.SelectMode, font=font)
|
||||||
for item in element.Values:
|
for item in element.Values:
|
||||||
element.TKListbox.insert(tk.END, item)
|
element.TKListbox.insert(tk.END, item)
|
||||||
element.TKListbox.selection_set(0,0)
|
element.TKListbox.selection_set(0,0)
|
||||||
|
@ -1462,10 +1512,11 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
element.TKListbox.configure(background=element.BackgroundColor)
|
element.TKListbox.configure(background=element.BackgroundColor)
|
||||||
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
|
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
|
||||||
element.TKListbox.configure(fg=text_color)
|
element.TKListbox.configure(fg=text_color)
|
||||||
# vsb = tk.Scrollbar(tk_row_frame, orient="vertical", command=element.TKListbox.yview)
|
vsb = tk.Scrollbar(listbox_frame, orient="vertical", command=element.TKListbox.yview)
|
||||||
# element.TKListbox.configure(yscrollcommand=vsb.set)
|
element.TKListbox.configure(yscrollcommand=vsb.set)
|
||||||
element.TKListbox.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1])
|
element.TKListbox.pack(side=tk.LEFT)
|
||||||
# vsb.pack(side=tk.LEFT, fill='y')
|
vsb.pack(side=tk.LEFT, fill='y')
|
||||||
|
listbox_frame.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1])
|
||||||
# ------------------------- INPUT MULTI LINE element ------------------------- #
|
# ------------------------- INPUT MULTI LINE element ------------------------- #
|
||||||
elif element_type == ELEM_TYPE_INPUT_MULTILINE:
|
elif element_type == ELEM_TYPE_INPUT_MULTILINE:
|
||||||
default_text = element.DefaultText
|
default_text = element.DefaultText
|
||||||
|
@ -1555,15 +1606,23 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
element.TKOut.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1])
|
element.TKOut.pack(side=tk.LEFT,padx=element.Pad[0], pady=element.Pad[1])
|
||||||
# ------------------------- IMAGE Box element ------------------------- #
|
# ------------------------- IMAGE Box element ------------------------- #
|
||||||
elif element_type == ELEM_TYPE_IMAGE:
|
elif element_type == ELEM_TYPE_IMAGE:
|
||||||
photo = tk.PhotoImage(file=element.Filename)
|
if element.Filename is not None:
|
||||||
if element_size == (None, None) or element_size == None or element_size == toplevel_form.DefaultElementSize:
|
photo = tk.PhotoImage(file=element.Filename)
|
||||||
width, height = photo.width(), photo.height()
|
elif element.Data is not None:
|
||||||
|
photo = tk.PhotoImage(data=element.Data)
|
||||||
else:
|
else:
|
||||||
width, height = element_size
|
photo = None
|
||||||
tktext_label = tk.Label(tk_row_frame, image=photo, width=width, height=height, bd=border_depth)
|
print('*ERROR laying out form.... Image Element has no image specified*')
|
||||||
tktext_label.image = photo
|
|
||||||
# tktext_label.configure(anchor=tk.NW, image=photo)
|
if photo is not None:
|
||||||
tktext_label.pack(side=tk.LEFT)
|
if element_size == (None, None) or element_size == None or element_size == toplevel_form.DefaultElementSize:
|
||||||
|
width, height = photo.width(), photo.height()
|
||||||
|
else:
|
||||||
|
width, height = element_size
|
||||||
|
element.tktext_label = tk.Label(tk_row_frame, image=photo, width=width, height=height, bd=border_depth)
|
||||||
|
element.tktext_label.image = photo
|
||||||
|
# tktext_label.configure(anchor=tk.NW, image=photo)
|
||||||
|
element.tktext_label.pack(side=tk.LEFT, padx=element.Pad[0],pady=element.Pad[1])
|
||||||
# ------------------------- SLIDER Box element ------------------------- #
|
# ------------------------- SLIDER Box element ------------------------- #
|
||||||
elif element_type == ELEM_TYPE_INPUT_SLIDER:
|
elif element_type == ELEM_TYPE_INPUT_SLIDER:
|
||||||
slider_length = element_size[0] * CharWidthInPixels()
|
slider_length = element_size[0] * CharWidthInPixels()
|
||||||
|
@ -1579,12 +1638,13 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
||||||
range_to = element.Range[1]
|
range_to = element.Range[1]
|
||||||
tkscale = tk.Scale(tk_row_frame, orient=element.Orientation, variable=element.TKIntVar, from_=range_from, to_=range_to, length=slider_length, width=slider_width , bd=element.BorderWidth, relief=element.Relief, font=font)
|
tkscale = tk.Scale(tk_row_frame, orient=element.Orientation, variable=element.TKIntVar, from_=range_from, to_=range_to, length=slider_length, width=slider_width , bd=element.BorderWidth, relief=element.Relief, font=font)
|
||||||
# tktext_label.configure(anchor=tk.NW, image=photo)
|
# tktext_label.configure(anchor=tk.NW, image=photo)
|
||||||
|
tkscale.config(highlightthickness=0)
|
||||||
if element.BackgroundColor is not None:
|
if element.BackgroundColor is not None:
|
||||||
tkscale.configure(background=element.BackgroundColor)
|
tkscale.configure(background=element.BackgroundColor)
|
||||||
tkscale.config(troughcolor=DEFAULT_SCROLLBAR_COLOR)
|
tkscale.config(troughcolor=DEFAULT_SCROLLBAR_COLOR)
|
||||||
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
|
if text_color is not None and text_color != COLOR_SYSTEM_DEFAULT:
|
||||||
tkscale.configure(fg=text_color)
|
tkscale.configure(fg=text_color)
|
||||||
tkscale.pack(side=tk.LEFT)
|
tkscale.pack(side=tk.LEFT, padx=element.Pad[0],pady=element.Pad[1])
|
||||||
#............................DONE WITH ROW pack the row of widgets ..........................#
|
#............................DONE WITH ROW pack the row of widgets ..........................#
|
||||||
# done with row, pack the row of widgets
|
# done with row, pack the row of widgets
|
||||||
tk_row_frame.grid(row=row_num+2, sticky=tk.NW, padx=DEFAULT_MARGINS[0])
|
tk_row_frame.grid(row=row_num+2, sticky=tk.NW, padx=DEFAULT_MARGINS[0])
|
||||||
|
@ -1698,7 +1758,7 @@ def StartupTK(my_flex_form):
|
||||||
root = tk.Tk() if not ow else tk.Toplevel()
|
root = tk.Tk() if not ow else tk.Toplevel()
|
||||||
if my_flex_form.BackgroundColor is not None:
|
if my_flex_form.BackgroundColor is not None:
|
||||||
root.configure(background=my_flex_form.BackgroundColor)
|
root.configure(background=my_flex_form.BackgroundColor)
|
||||||
_my_windows.NumOpenWindows += 1
|
_my_windows.Increment()
|
||||||
|
|
||||||
my_flex_form.TKroot = root
|
my_flex_form.TKroot = root
|
||||||
# root.protocol("WM_DELETE_WINDOW", MyFlexForm.DestroyedCallback())
|
# root.protocol("WM_DELETE_WINDOW", MyFlexForm.DestroyedCallback())
|
||||||
|
@ -1716,7 +1776,7 @@ def StartupTK(my_flex_form):
|
||||||
my_flex_form.TKroot.mainloop()
|
my_flex_form.TKroot.mainloop()
|
||||||
# print('..... BACK from MainLoop')
|
# print('..... BACK from MainLoop')
|
||||||
if not my_flex_form.FormRemainedOpen:
|
if not my_flex_form.FormRemainedOpen:
|
||||||
_my_windows.NumOpenWindows -= 1 * (_my_windows.NumOpenWindows != 0) # decrement if not 0
|
_my_windows.Decrement()
|
||||||
if my_flex_form.RootNeedsDestroying:
|
if my_flex_form.RootNeedsDestroying:
|
||||||
my_flex_form.TKroot.destroy()
|
my_flex_form.TKroot.destroy()
|
||||||
my_flex_form.RootNeedsDestroying = False
|
my_flex_form.RootNeedsDestroying = False
|
||||||
|
@ -1992,8 +2052,8 @@ def _ProgressMeterUpdate(bar, value, text_elem, *args):
|
||||||
bar.ParentForm._Close()
|
bar.ParentForm._Close()
|
||||||
if bar.ParentForm.RootNeedsDestroying:
|
if bar.ParentForm.RootNeedsDestroying:
|
||||||
try:
|
try:
|
||||||
_my_windows.NumOpenWindows -= 1 * (_my_windows.NumOpenWindows != 0) # decrement if not 0
|
|
||||||
bar.ParentForm.TKroot.destroy()
|
bar.ParentForm.TKroot.destroy()
|
||||||
|
_my_windows.Decrement()
|
||||||
except: pass
|
except: pass
|
||||||
bar.ParentForm.RootNeedsDestroying = False
|
bar.ParentForm.RootNeedsDestroying = False
|
||||||
bar.ParentForm.__del__()
|
bar.ParentForm.__del__()
|
||||||
|
|
Loading…
Reference in New Issue