【发布时间】:2020-06-22 18:34:33
【问题描述】:
所以我有一个场景,当必须创建“n”个独立无线电组时,我们将能够独立地检索每个无线电组的值。
当前代码为我提供了最后一个单选组的值,与我按下的按钮无关。
import tkinter # note that module name has changed from Tkinter in Python 2 to tkinter in Python 3
from tkinter import *
from tkinter import messagebox
top = tkinter.Tk()
top.title("NA")
a = int(input("Enter the number of frames"))
btn = [""]*a
def commd():
print(i)
print("Value changed to new value", values[i],'with value', values[i].get())
#print('Update in value')
values = [tkinter.IntVar() for i in range(len(btn))]
print(len(values))
for i in range(len(btn)):
print(i)
txt = "Button_Number", (i+1)
rtxt1 = 'Radio Button1',i+1
rtxt2 = 'Radio Button2',i+1
abc = Button(top, text = txt, activebackground = "Green", fg = "Blue", bg = "Red", height =5, command = aa)
R1 = Radiobutton(top, text = "START", activebackground = "Green", fg = "Blue", bg = "Red", height = 2,variable = values[i],value=0,command = commd)
R2 = Radiobutton(top, text = "STOP", activebackground = "Green", fg = "Blue", bg = "Red", height = 2,variable = values[i],value=1,command = commd)
abc.grid(row = i+i, column = 0,rowspan = 2)
R1.grid(row = i+i, column = 1)
R2.grid(row = i+i+1,column = 1)
mainloop()
【问题讨论】:
标签: python tkinter radio-button