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! -
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()
-
You only have one variable for the button objects and one variable for all the buttons. You need a button for each position and a variable for each button. - self.Button_Name = [[Checkbutton() for i in range(self.rows)] for j in range(self.cols)]
-
-
self.buttonChecked = [[BooleanVar() for i in range(self.rows)] for j in range(self.cols)]
You must have a way to "freeze" the row and column numbers to know which column or row to toggle on or off. - for boat_num in range(self.cols):
-
for boat_slot in range(self.rows):
-
-
def handler_col(i=boat_num):
-
return self.select_full_column(i)
-
def handler_row(i=boat_slot):
-
return self.select_full_row(i)
Assign the appropriate handler function: - 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 = handler_col)
-
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 = handler_row)
The row and column toggle functions: - def select_full_column(self, i):
-
for j in range(1, self.rows):
-
self.Button_Name[i][j].toggle()
-
-
def select_full_row(self, i):
-
for j in range(1, self.cols):
-
self.Button_Name[j][i].toggle()
2 1888 bvdet 2,851
Expert Mod 2GB
You only have one variable for the button objects and one variable for all the buttons. You need a button for each position and a variable for each button. - self.Button_Name = [[Checkbutton() for i in range(self.rows)] for j in range(self.cols)]
-
-
self.buttonChecked = [[BooleanVar() for i in range(self.rows)] for j in range(self.cols)]
You must have a way to "freeze" the row and column numbers to know which column or row to toggle on or off. - for boat_num in range(self.cols):
-
for boat_slot in range(self.rows):
-
-
def handler_col(i=boat_num):
-
return self.select_full_column(i)
-
def handler_row(i=boat_slot):
-
return self.select_full_row(i)
Assign the appropriate handler function: - 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 = handler_col)
-
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 = handler_row)
The row and column toggle functions: - def select_full_column(self, i):
-
for j in range(1, self.rows):
-
self.Button_Name[i][j].toggle()
-
-
def select_full_row(self, i):
-
for j in range(1, self.cols):
-
self.Button_Name[j][i].toggle()
Your suggestions work great! I merged your changes in and it worked exactly what I want. Thanks a lot for your help!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Askari |
last post by:
Hi,
How do for do a "select()" on a CheckButton in a menu (make with
add_checkbutton(....) )?
I can modify title, state, etc but not the "check state". :-(
Askari
|
by: Elaine Jackson |
last post by:
My CheckButton variables seem always to be true, whether the box is checked or
not, which makes them considerably less useful. Following is a little script
that illustrates the difficulty. Any help...
|
by: Tuvas |
last post by:
I want to have a checkbutton that when it is pushed will do a function
depending on if it was pushed before or not. Ei:
b=checkbutton(command=check)
b.grid(row=0,column=0)
def check():
if...
|
by: Knepper, Michelle |
last post by:
Hi out there,
I'm a first-time user of the "Copy ... From..." command, and I'm trying
to load a table from a text flat file.
http://www.postgresql.org/docs/7.4/static/sql-copy.html
I don't...
|
by: Muleskinner |
last post by:
Hi group,
One simple question: How to create a checkbutton in vb.net?
In vb6.0 it was easily done by changing the style of the checkbox control, but how to do it in vb.net...
Regards Thomas
|
by: Thomas Jansson |
last post by:
Dear all
I am writing a program with tkinter where I have to create a lot of
checkbuttons. They should have the same format but should have
different names. My intention is to run the functions...
|
by: Giovanni D'Ascola |
last post by:
Hi.
I noticed that <input type="reset"actually don't enable checkbutton
which are checked by default after they have been disabled by
javascript. It's a bug?
|
by: jayro |
last post by:
Hi folks,
I got a checkbutton with a large label which is being wrapped into a few lines.
Due to the height of the label, the checkbutton aligns vertically ending up set on the center of its...
|
by: dudeja.rajat |
last post by:
Hi,
I've a checkbutton in my GUI application which I want to work as:
1. it should be un-ticked by default,
2. should display a label in Gui, by default,
3. when user ticks the check button...
|
by: Gabriel Genellina |
last post by:
En Thu, 21 Aug 2008 05:07:45 -0300, <dudeja.rajat@gmail.comescribi�:
Use the grid_forget method to hide the label. Based on your posted example:
from Tkinter import *
def onclick():
if...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |