1
我正在为涉及python和tkinter的计算机科学类开发一个项目。我正在努力打造一款功能齐全的大富翁游戏,并且它的进展顺利。我终于碰到了一个我似乎无法克服的障碍。我试图做一个接口来抵押用户的属性,我想用tkinter checkbuttons来获得用户输入,然后抵押所有被检查的属性。这里是类的我所做的片段:使用未知量的复选框创建窗口 - Python/tkinter
from tkinter import *
class Mortgager(Tk):
def __init__(self,coorder): # 'coorder' is a class that coordinates all of the
self.coorder = coorder # other classes together
Tk.__init__(self,className='Mortgager')
self.title('Mortgaging')
self.cbuttons = []
self.intvars = []
for prop in coorder.active_player.properties: # iterate through player's currently owned properties
if not prop.mortgaged:
self.intvars.append(IntVar(self,0))
self.cbuttons.append(Checkbutton(self,
variable=self.intvars[-1],text=prop.get_name(),
# Most recent intvar, method returns name of property
command=self.update_cash_onscreen)
#### Not sure what to do here...
self.cbuttons[-1].var = self.intvars[-1]
self.cbuttons[-1].text = prop.get_name()
i = 0
for cbutton in self.cbuttons: # Every three properties, new column
cbutton.grid(column=i//3,row=i%3,sticky=W,
padx=5,pady=5)
i += 1
# Haven't finished the rest of the class...
我的问题是:如何创建checkbuttons任意数量的,然后告诉它checkbuttons已被点击“在路上”更新某种Label
显示当前的抵押金额,StringVar
或类似的东西,然后做一些与总金额?
在此先感谢!