Python tkinter 检查按钮打印 PY_VAR0 [英] Python tkinter check button printing PY_VAR0
本文介绍了Python tkinter 检查按钮打印 PY_VAR0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以这是从这个问题中大量汲取的代码:
So this is the code, which draws heavily from this question:
如何从 python tkinter 的 for 循环中的列表创建多个复选框.
from tkinter import *
root = Tk()
enable = {'jack': 0, 'john': 1}
def actright(x):
print(enable.get(x))
for machine in enable:
enable[machine] = Variable()
l = Checkbutton(root, text=machine, variable=enable[machine],
command= actright(machine))
l.pack(anchor = W)
root.mainloop()
我希望输出是:
0
1
相反的输出是:
PY_VAR0
PY_VAR1
如果没有数字前面的PY_VAR",我如何获得这些值?
How can I get these values without the "PY_VAR" preceding the number?
推荐答案
去掉enable[machine] = Variable()
for machine in enable:
l = Checkbutton(root, text=machine, variable=enable[machine],
command= actright(machine))
l.pack(anchor = W)
root.mainloop()
您看到 PY_VAR0
和 PY_VAR1
是因为您使用 enable[machine] = Variable()
将值设置为那些值,这会覆盖这些值在你的字典中,所以你得到你所做的输出是有道理的.
You see PY_VAR0
and PY_VAR1
because you set the values to those with enable[machine] = Variable()
, that overwrites the values in your dict so it makes sense that you get the output you do.
这篇关于Python tkinter 检查按钮打印 PY_VAR0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文