<p>首先,获取<code>PY_VARXX</code>而不是变量类中的内容表示缺少<code>get()</code>。你知道吗</p>
<p>替换:</p>
<pre><code>print(self.smuChoices[0])
</code></pre>
<p>使用:</p>
<pre><code>print(self.smuChoices[0].get())
</code></pre>
<p>第二,如果您想在<code>label</code>、<code>button</code>等上显示变量类的值,您可以通过简单地将变量类赋给它来使用<code>textvariable</code>选项。你知道吗</p>
<p>替换:</p>
<pre><code>tk.Label(self.smuName,text=SMU).grid()
</code></pre>
<p>使用:</p>
<pre><code>tk.Label(self.smuName, textvariable=self.smuChoices[val]).grid()
</code></pre>
<hr/>
<p>你的问题我还是有点不清楚,但我会尽我所能给出一个答案。你知道吗</p>
<p>据我所知,您正试图为给定的项目列表创建一组<code>Checkbutton</code>。下面是一个方法示例,该方法将<code>items</code>作为参数,并返回一个复选框字典,其中<code>root</code>作为其父项:</p>
<pre><code>import tkinter as tk
def dict_of_cbs(iterable, parent):
if iterable:
dict_of_cbs = dict()
for item in iterable:
dict_of_cbs[item] = tk.Checkbutton(parent)
dict_of_cbs[item]['text'] = item
dict_of_cbs[item].pack() # it's probably a better idea to manage
# geometry in the same place wherever
# the parent is customizing its
# children's layout
return dict_of_cbs
if __name__ == '__main__':
root = tk.Tk()
items = ("These", "are", "some", "items.")
my_checkboxes = dict_of_cbs(items, root)
root.mainloop()
</code></pre>
<p>另外请注意,在这种特殊情况下,我没有使用任何变量类(<code>BooleanVar</code>、<code>DoubleVar</code>、<code>IntVar</code>或<code>StringVar</code>)作为<a href="https://stackoverflow.com/q/47334885/7032856">they seem to be redundant</a>。你知道吗</p>