문제

I'm using Python and Tkinter and was wondering whether there is anyway I could do something like this because currently it gives me an error. I would like to be able to configure a widget with user input as a string to decide what to configure, hence why the variable 'string_variable' needs to be a string.

tk_widget.config(string_variable = variable)

At the moment, I get an error saying "TclError: unknown option -'string_of_stringvar_here'" Please help me! Thank you for your replies in advance. - Ed

도움이 되었습니까?

해결책

You can treat a widget like a dictionary, with attributes being keys. For example:

label = tk.Label(root)
...
some_attribute = "background"
some_value = "red"
label[some_attribute] = some_value

You can also build up a dictionary of attributes and values, and pass that to the config method:

values = {some_attribute: some_value}
label.config(values)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top