Why Is My Python Function Printing Out {}main And Not Just Main?
I am using a function to grab my data from a json file and print it to a tkinter combo box, for some reason the first word always has {} in front of it. My json data doesn't have i
Solution 1:
Question: Why is my python function printing out
'{}Main'
and not just 'Main'
?
- Initalizing
profiles_select['values']
This results, widget internal, to:profiles_select = ttk.Combobox(new_task_frame1, width=10, values=[])
''
,tcl
uses:'{}'
- Adding options
You take the internal valueprofiles_select['values'] = (profiles_select['values'], add_profile)
''
and a new option'Main'
, which results in('', 'Main')
.
How
tkinter
shows theListbox
optionsYour two options:
{}Main Test
More than two options:
profiles_select['values'] = ('{{{} Main} Test} Test2', 'Test3') {{{} Main} Test} Test2 Test3
Conclusion, don't update options using:
profiles_select['values'] = (profiles_select['values'], add_profile)
Solution: Create your sequence first and assign it in whole once.
withopen('profiles.txt', 'r') as file:
profiles = json.load(file)
options = []
for profile in profiles:
options.append(profile['profile_name'])
profiles_select['values'] = options
Post a Comment for "Why Is My Python Function Printing Out {}main And Not Just Main?"