Dear experts:
I am trying to write one slot matrix manager which consists of 4 columns and 24 rows (total 96 slots). So I put one checkbutton matrix with 5 columns and 25 rows slot.
The check/uncheck of checkbutton[0][0] will toggle all 96 slots.
The check/uncheck of checkbutton[1][0] will toggle all 24 slots in column 1.
The check/uncheck of checkbutton[0][1] will toggle all 4 slots in row 1.
The check/uncheck of checkbutton[1][1] will toggle only slot in row 1 column 1.
and so on...
I wrote the script but it doesn't work as I expected. Any check/uncheck in any checkbuttons will select/deselect all checkbuttons. Looks like I didn't use the command argument correctly in checkbutton. Could you please help me out?
Following is my script and thanks a lot for your help!
I am trying to write one slot matrix manager which consists of 4 columns and 24 rows (total 96 slots). So I put one checkbutton matrix with 5 columns and 25 rows slot.
The check/uncheck of checkbutton[0][0] will toggle all 96 slots.
The check/uncheck of checkbutton[1][0] will toggle all 24 slots in column 1.
The check/uncheck of checkbutton[0][1] will toggle all 4 slots in row 1.
The check/uncheck of checkbutton[1][1] will toggle only slot in row 1 column 1.
and so on...
I wrote the script but it doesn't work as I expected. Any check/uncheck in any checkbuttons will select/deselect all checkbuttons. Looks like I didn't use the command argument correctly in checkbutton. Could you please help me out?
Following is my script and thanks a lot for your help!
Code:
from Tkinter import *
from tkMessageBox import *
class BoatManager( Frame ):
def __init__( self, cols, rows ):
Frame.__init__( self )
self.cols = cols
self.rows = rows
self.master.title( "Demo" )
# main frame fills entire container, expands if necessary
self.master.rowconfigure( 0, weight = 1 )
self.master.columnconfigure( 0, weight = 1 )
self.grid( sticky = W+E+N+S )
## self.buttonChecked = BooleanVar()
tempbutton = Checkbutton()
self.Button_Name = [[tempbutton]*self.rows]*self.cols
tempvar = BooleanVar()
self.buttonChecked = [[tempvar]*self.rows]*self.cols
for boat_num in range(self.cols):
for boat_slot in range(self.rows):
if boat_slot == 0 and boat_num == 0:
self.Button_Name[boat_num][boat_slot] = Checkbutton(self, text = 'All Boats_Slots', padx=5, pady=5, relief = SUNKEN, width = 15,
variable = self.buttonChecked[boat_num][boat_slot], command = self.select_all_boats)
elif boat_slot == 0:
self.Button_Name[boat_num][boat_slot] = Checkbutton(self, text = 'Boat_' + str(boat_num), padx=5, pady=5, relief = SUNKEN, width = 15,
variable = self.buttonChecked[boat_num][boat_slot], command = self.select_full_column)
elif boat_num == 0:
self.Button_Name[boat_num][boat_slot] = Checkbutton(self, text = 'Slot_' + str(boat_slot), padx=5, pady=5, relief = SUNKEN, width = 15,
variable = self.buttonChecked[boat_num][boat_slot], command = self.select_full_row)
else:
self.Button_Name[boat_num][boat_slot] = Checkbutton(self, text = str(boat_num) + '_' + str(boat_slot), padx=5, pady=5, relief = SUNKEN,
variable = self.buttonChecked[boat_num][boat_slot], width = 15, command = self.select_current_slot)
self.Button_Name[boat_num][boat_slot].grid(row = boat_slot+1, rowspan = 1, column = boat_num + 2, columnspan = 1)
def select_all_boats(self):
for boat_num in xrange(self.cols):
for boat_slot in xrange(self.rows):
if boat_slot != 0 and boat_num != 0:
self.Button_Name[boat_num][boat_slot].toggle()
## def select_full_column(self, column_num):
## for boat_slot in xrange(25):
## if boat_slot != 0:
## self.Button_Name[column_num][boat_slot].toggle()
def select_full_column(self):
print "I am here"
pass
## def select_full_row(self, row_num):
## for boat_num in xrange(5):
## if boat_num != 0:
## self.Button_Name[boat_num][row_num].toggle()
def select_full_row(self):
pass
def select_current_slot(self):
pass
##if __name__ == "__main__":
## BoatManager(5,25).mainloop()
BoatManager(5,25).mainloop()
Comment