Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [Tkinter] Manipulating Checkboxes
#1
Hi, I have this Checkboxes, İmage

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]
Quote
#2
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)
Output:
"categorie" IN (\'activites diversifiees\', \'conservation\', \'infrastructure\', \'institution\', \'parc\')
Quote
#3
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
Quote
#4
Use the above instead of using if /else statements
Quote
#5
Thanks, Yoriz

your the best it worked
Quote
#6
Hi Yoriz
could you make the output like

Output:
\"categorie\" IN (\'activites diversifiees\', \'conservation\', \'infrastructure\', \'institution\', \'parc\')
Quote
#7
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)
Output:
\"categorie\" IN (\'activites diversifiees\', \'conservation\', \'infrastructure\', \'institution\', \'parc\')
Quote
#8
Thanks Yoriz....
Quote
#9
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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Checkboxes in different frames misbehave octoeder 3 1,573 Oct-03-2018, 09:12 AM
Last Post: jfong
  [Tkinter] Print if all checkboxes marked Kaelmi 10 11,661 May-24-2017, 02:17 PM
Last Post: buran
  [WxPython] Setting interdependencies between checkboxes merlem 2 1,760 Feb-12-2017, 07:51 PM
Last Post: merlem

Forum Jump:


Users browsing this thread: 1 Guest(s)