我正在创建一个全局数据字典,从中我将在我的字典中显示各种数据。字典的两个元素是一个列表和一个布尔变量。我想在 CheckButton 小部件中使用 BooleanVar()。该字典用于存储我想在我的 gui 中显示的各种机器子系统的信息。gui 的一个功能是能够在用户希望的情况下排除频道,这意味着停止监视。机器通道是字典键,带有一个列表和一个布尔变量。该列表包含一些用于确定通道状态的初始数据。BooleanVar() 我想添加到一个复选按钮,以便用户可以在排除/包含通道 gui 之间切换。channelListFull = {'sys1:channel1': (['Label1', 'GOOD', 0, 0],BooleanVar()), 'sys1:channel2': (['Label2', 'GOOD', 0, 0],BooleanVar()), 'sys2:channel1': (['Label3', 'GOOD', 0, 0],BooleanVar())etc...其余代码(大致,不完全可执行)如下class ChannelDisplay(Frame) def __init__(self, master=None, label='NONE', channel='NONE',**kw): Frame.__init(self, master, **kw) self.lbl = label self.chnl = channel self.component = tk.Label(self, text=self.lbl) self.component.grid self.toggle = tk.Checkbutton(self,variable=channelListFull[channel][1]) self.toggle.gridclass Application(Frame): def __init__(self,master=None): Frame.__init__(self,master) self.monitoring() def monitor(self): channelRemoveList = [] for entry in channelListFull.keys(): badChannel = channelListFull[entry][1].get() if not badChannel : channelRemoveList.append(entry) #This is a separate function that modifies which channels are included in the monitoring process for entry in channelListFull.keys(): self.chan = ChannelDisplay(root,label=channelListFull[0][0],channel=entry) self.chan.grid()root = Tk()app=application(master=root)app.mainloop()我在创建的行中收到错误channelListFull消息: Exception AttributeError: "BooleanVar instance has no attribute '_tk'" in <bound method BooleanVar.__del__ of <Tkinter.BooleanVar instance at 0x7f39981b77e8>> ignored
添加回答
举报
0/150
提交
取消