New way to configure comboboxes (not working)

This commit is contained in:
MikeTheWatchGuy 2019-01-01 14:49:14 -05:00
parent e38bd93059
commit 791b908e17
2 changed files with 38 additions and 56 deletions

View File

@ -20,6 +20,7 @@ import datetime
import textwrap import textwrap
import pickle import pickle
import calendar import calendar
from random import randint
g_time_start = 0 g_time_start = 0
g_time_end = 0 g_time_end = 0
@ -5015,66 +5016,47 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
element.TKStringVar = tk.StringVar() element.TKStringVar = tk.StringVar()
style_name = 'TCombobox' style_name = 'TCombobox'
if element.TextColor is not None and element.TextColor != COLOR_SYSTEM_DEFAULT: if element.TextColor is not None and element.TextColor != COLOR_SYSTEM_DEFAULT:
# print('Combo special style', element.TextColor, element.BackgroundColor) # Creates 1 style per Text Color/ Background Color combination
style_name = 'PSG.TCombobox' style_name = element.TextColor + element.BackgroundColor + '.TCombobox'
print(style_name)
combostyle = ttk.Style() combostyle = ttk.Style()
#
# combostyle.map("C.TButton", # Creates a unique name for each field element(Sure there is a better way to do this)
# foreground=[('pressed', 'red'), ('active', 'blue')], unique_field = str(datetime.datetime.today().timestamp()).replace('.','') + '.TCombobox.field'
# background=[('pressed', '!disabled', 'black'), ('active', 'white')] # unique_field = str(randint(1,50000000)) + '.TCombobox.field'
# )
# combostyle.map('PSG.TCombobox', background=[('selected', 'green')]) print(unique_field)
# combostyle.configure('PSG.TCombobox.Listbox',foreground='green') # Clones over the TCombobox.field element from the "alt" theme.
# combostyle.map('PSG.TCombobox', foreground=[('active','purple')]) # This is what will allow us to change the background color without altering the whole programs theme
# combostyle.map('PSG.TCombobox.textarea', foreground=[('active','purple')]) combostyle.element_create(unique_field, "from", "alt")
# combostyle.map('PSG.TCombobox.rightdownarrow', arrowcolor=[('active','purple')])
# combostyle.configure('PSG.TCombobox.TEntry', background='red') # Create widget layout using cloned "alt" field
# combostyle.configure('PSG.TCombobox', background=element.BackgroundColor) combostyle.layout(style_name, [
combostyle.configure('PSG.TCombobox', foreground=element.TextColor) # WORKS (unique_field, {'children': [('Combobox.downarrow', {'side': 'right', 'sticky': 'ns'}),
combostyle.configure('PSG.TCombobox', selectbackground='gray70') # WORKS ('Combobox.padding',
combostyle.configure('PSG.TCombobox', selectforeground=element.TextColor) # WORKS {'children': [('Combobox.focus',
# combostyle.configure('PSG.TCombobox.Listbox', background='purple') {'children': [('Combobox.textarea',
# toplevel_form.TKroot.option_add("*TCombobox*Background", element.BackgroundColor) # WORK for drop-down list (Changes all) {'sticky': 'nswe'})],
# combostyle.map('PSG.TCombobox', background=[('active', 'purple'), ('disabled', 'purple')]) 'expand': '1',
# combostyle.configure('PSG.TCombobox.PopdownFrame', background=element.BackgroundColor) 'sticky': 'nswe'})],
# combostyle.configure('PSG.TCombobox.field', fieldbackground=element.BackgroundColor) 'expand': '1',
# combostyle.configure('PSG.TCombobox.Listbox', background=element.BackgroundColor) 'sticky': 'nswe'})],
# print(combostyle.element_names()) 'sticky': 'nswe'})])
# print(combostyle.element_options('PSG.TCombobox'))
# try: # Copy default TCombobox settings
# combostyle.theme_create('combostyle', combostyle.configure(style_name, *combostyle.configure("TCombobox"))
# settings={'TCombobox':
# {'configure': # Set individual widget options
# {'selectbackground': 'gray50', combostyle.configure(style_name, foreground=element.TextColor)
# 'fieldbackground': element.BackgroundColor, combostyle.configure(style_name, selectbackground='gray70')
# 'foreground': text_color, combostyle.configure(style_name, fieldbackground=element.BackgroundColor)
# 'background': element.BackgroundColor} combostyle.configure(style_name, selectforeground=element.TextColor)
# }})
# except:
# try:
# combostyle.theme_settings('combostyle',
# settings={'TCombobox':
# {'configure':
# {'selectbackground': 'gray50',
# 'fieldbackground': element.BackgroundColor,
# 'foreground': text_color,
# 'background': element.BackgroundColor}
# }})
# except:
# pass
# # ATTENTION: this applies the new style 'combostyle' to all ttk.Combobox
# combostyle.theme_use('combostyle')
element.TKCombo = ttk.Combobox(tk_row_frame, width=width, textvariable=element.TKStringVar, font=font, style=style_name) element.TKCombo = ttk.Combobox(tk_row_frame, width=width, textvariable=element.TKStringVar, font=font, style=style_name)
if element.Size[1] != 1 and element.Size[1] is not None: if element.Size[1] != 1 and element.Size[1] is not None:
element.TKCombo.configure(height=element.Size[1]) element.TKCombo.configure(height=element.Size[1])
# element.TKCombo['state']='readonly'
element.TKCombo['values'] = element.Values element.TKCombo['values'] = element.Values
# if element.InitializeAsDisabled:
# element.TKCombo['state'] = 'disabled'
# if element.BackgroundColor is not None:
# element.TKCombo.configure(background=element.BackgroundColor)
element.TKCombo.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1]) element.TKCombo.pack(side=tk.LEFT, padx=elementpad[0], pady=elementpad[1])
if element.Visible is False: if element.Visible is False:
element.TKCombo.pack_forget() element.TKCombo.pack_forget()
@ -7353,7 +7335,7 @@ def PopupGetText(message, title=None, default_text='', password_char='', size=(N
def main(): def main():
from random import randint from random import randint
ChangeLookAndFeel('GreenTan') ChangeLookAndFeel('Black')
# ------ Menu Definition ------ # # ------ Menu Definition ------ #
menu_def = [['&File', ['!&Open', '&Save::savekey', '---', '&Properties', 'E&xit']], menu_def = [['&File', ['!&Open', '&Save::savekey', '---', '&Properties', 'E&xit']],
['!&Edit', ['!&Paste', ['Special', 'Normal', ], 'Undo'], ], ['!&Edit', ['!&Paste', ['Special', 'Normal', ], 'Undo'], ],

View File

@ -4573,7 +4573,7 @@ if sys.version_info[0] >= 3:
return return_val return return_val
else: else:
def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False): def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False):
if isinstance(sub_menu_info, (str,unicode)): if not isinstance(sub_menu_info, list):
if not is_sub_menu and not skip: if not is_sub_menu and not skip:
# print(f'Adding command {sub_menu_info}') # print(f'Adding command {sub_menu_info}')
pos = sub_menu_info.find('&') pos = sub_menu_info.find('&')
@ -4600,7 +4600,7 @@ else:
while i < (len(sub_menu_info)): while i < (len(sub_menu_info)):
item = sub_menu_info[i] item = sub_menu_info[i]
if i != len(sub_menu_info) - 1: if i != len(sub_menu_info) - 1:
if not isinstance(sub_menu_info[i + 1], (str, unicode)): if isinstance(sub_menu_info[i + 1], list):
new_menu = tk.Menu(top_menu, tearoff=element.Tearoff) new_menu = tk.Menu(top_menu, tearoff=element.Tearoff)
pos = sub_menu_info[i].find('&') pos = sub_menu_info[i].find('&')
if pos != -1: if pos != -1: