我是 python 新手,我的任务是从列表框中获取输入并为每个条目创建单选按钮。在我的代码中,我可以创建单选按钮,但是当我单击它们时它们不起作用,即在这种情况下它们不会打印“hello”和数字 i。这是代码:
def generateGraph():
w = Toplevel(bg = "grey")
w.resizable(0,0)
frameData = Frame(w, bg="grey", padx=10, pady=10)
frameData.grid(row = 0, column=0, pady = 1, padx = 1, sticky = N+E+S+W)
InputLabel = Label(frameData, text="Inputs:", bg="grey")
InputLabel.grid(row=1, column=0, padx=10, sticky=N+E+S+W)
OutputLabel = Label(frameData, text="Outputs:", bg="grey")
OutputLabel.grid(row=1, column=1, padx=10, sticky=N+E+S+W)
i=0
c=[]
inputVar = IntVar()
while(InputBox.get(i)):
c.append(Radiobutton(frameData, text=InputBox.get(i), variable=inputVar, value = i, background="grey", command= hello(i)))
c[i].grid(row = i+2, column = 0, sticky = W)
i=i+1
if makemodal:
w.focus_set()
w.grab_set()
w.wait_window()
def hello(i):
print("hello %d" %i)
请提前帮助和感谢。