[Tkinter] Manipulating Checkboxes - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] Manipulating Checkboxes (/thread-18954.html) |
Manipulating Checkboxes - teflon - Jun-07-2019 Hi, I have this Checkboxes, any combination can be selected, and each checkbox selected results in a different query. Instead of using if else, can someone suggest an alternative method, because the combination is gonna be endless [python] from tkinter import * import arcpy from tkinter import ttk def select_landuse(): arcpy.env.workspace = C:/Users/umroot/Documents/ArcGIS/Projects/RecentINSE6421project/affectationpu" in_features = "AffectationPU.shp" out_feature_class = "C:/Users/umroot/Documents/ArcGIS/Projects/RecentINSE6421project/pythonOutput/affectationpu" if (landuse1.get() and landuse3.get() and landuse4.get() and landuse5.get()and landuse6.get()and landuse7.get() and landuse10.get())==TRUE : where_clause= "\"categorie\" IN (\'activites diversifiees\',\'conservation\', \'emplois\', \'infrastructure\', \'institution\', \'mixte\', \'residentiel\')" elif(landuse1.get() and landuse3.get()and landuse4.get() and landuse5.get() and landuse6.get() and landuse7.get() and landuse8.get() and landuse9.get() and landuse10.get())==TRUE: where_clause="\"categorie\" IN (\'activites diversifiees\',\'conservation\', \'emplois\', \'infrastructure\', \'institution\', \'mixte\', \'residentiel\')" elif (landuse1.get()and landuse2.get() and landuse4.get()and landuse4.get()and landuse6.get()and landuse7.get()and landuse9.get() and landuse10.get())==TRUE: where_clause= "\"categorie\" IN (\'activites diversifiees\',\'conservation\', \'emplois\', \'infrastructure\', \'institution\', \'mixte\',\'religieux\',\'residentiel\')" elif (landuse1.get()and landuse2.get() and landuse3.get()and landuse4.get()and landuse4.get()and landuse6.get()and landuse7.get()and landuse9.get() and landuse10.get())==TRUE: where_clause= "\"categorie\" IN (\'activites diversifiees\',\'conservation\',\'agricole\', \'emplois\', \'infrastructure\', \'institution\', \'mixte\', \'religieux\',\'residentiel\')" elif (landuse1.get()and landuse2.get() and landuse3.get()and landuse4.get()and landuse4.get()and landuse6.get()and landuse7.get()and landuse8.get() and landuse10.get())==TRUE: where_clause= "\"categorie\" IN (\'activites diversifiees\',\'conservation\',\'agricole\', \'emplois\', \'infrastructure\', \'institution\', \'mixte\', \'parc\',\'residentiel\')"[/python] RE: Manipulating Checkboxes - Yoriz - Jun-07-2019 You could do something like this where controls is all the various checkbox controls ie landuse1.get() controls = (True, True, False, False, True, True, False, True, False) clauses = (r"\'activites diversifiees\'", r"\'conservation\'", r"\'agricole\'", r"\'emplois\'", r"\'infrastructure\'", r"\'institution\'", r"\'mixte\'", r"\'parc\'", r"\'residentiel\'") clauses = ', '.join(clause for clause, control in zip(clauses, controls) if control) where_clause = f"\"categorie\" IN ({clauses})" print(where_clause)
RE: Manipulating Checkboxes - teflon - Jun-07-2019 thank Yoriz but I don't understand how I could use the status (checked or unchecked ie landuse1.get())of the checkboxes in controls without using if /else statements RE: Manipulating Checkboxes - Yoriz - Jun-07-2019 Use the above instead of using if /else statements RE: Manipulating Checkboxes - teflon - Jun-10-2019 Thanks, Yoriz your the best it worked RE: Manipulating Checkboxes - teflon - Jun-10-2019 Hi Yoriz could you make the output like
RE: Manipulating Checkboxes - Yoriz - Jun-11-2019 Sure controls = (True, True, False, False, True, True, False, True, False) clauses = (r"\'activites diversifiees\'", r"\'conservation\'", r"\'agricole\'", r"\'emplois\'", r"\'infrastructure\'", r"\'institution\'", r"\'mixte\'", r"\'parc\'", r"\'residentiel\'") clauses = ', '.join(clause for clause, control in zip(clauses, controls) if control) where_clause = f'\\"categorie\\" IN ({clauses})' print(where_clause)
RE: Manipulating Checkboxes - teflon - Jun-11-2019 Thanks Yoriz.... RE: Manipulating Checkboxes - teflon - Oct-02-2019 Hello All, I need the python code for calculating the value of New_score for a column called ID_TRC using the values of 3 other columns called LENGTH, Category, and Score. The result is to be stored in a newly created new excel file for each unique ID_TRC and its corresponding New_Score. The image is a sample of the data The rules for calculating the new scores are: if ID_TRC exists elsewhere in the table, with a different LENGTH and different Category then the new_score = {SUM((Score X LENGTH))[sum for each rows with the same ID_TRC]}divided by (sum of LENGTHS of all with the same ID_TRC) if ID_TRC exists elsewhere in the table, with the same LENGTH and different Category then the new_score = {[u]SUM((Score X LENGTH))[sum for each rows with the same ID_TRC]} divided by LENGTH |