mardi 14 septembre 2021

Don't understand how to bind user click to a specific object within datafraame

I'm new to Python and I have the following code . When executed I get a GUI which allows me to check in /Out a checkbox . I have created an if statment to record the status of the clicking , however I don't understand how to bind the checkbox to a specific object within a dataframe (Pandas).The dataframe includes a list of objects that can user choose from ,so when the application save the data to csv file only the selected data will be saved . Right now I can't make it work . All the fields are saved to the csv file ,always .

Can you help me to understand what to do to make to be selectable ? Thx .

from tkinter import *
from tkinter import Scale
import tkinter as tk
from tkinter import filedialog
from tkinter import ttk
import ttkbootstrap
from termcolor import cprint ,colored
import pydicom
import pandas as pd
import os



 


        
   
print('Welcome to DTETool v1.1')
    

#Asking the user to choose input location

def filelocainput():
    filelocationinput = filedialog.askopenfilename()
    Data = pydicom.dcmread(filelocationinput , force = True )
   
         
 
   
    
  


    print('PatientID -',Data.PatientID)
    print('StudyID -',Data.StudyID)
    print('StudyDescription-',Data.StudyDescription)
    print('StudyDate -',Data.StudyDate)
    print('PatientName -' ,Data.PatientName)
    print('ScanOptions -' ,Data.ScanOptions)
    print('TotalCollimationWidth -',Data.TotalCollimationWidth)
    print('SeriesDescription',Data.SeriesDescription)
    print('SeriesNumber -',Data.SeriesNumber)
    print('PatientSex -' ,Data.PatientSex)
    print('SliceThickness -' ,Data.SliceThickness)
    print('ProtocolName -',Data.ProtocolName)
    print('BodyPartExamined -' ,Data.BodyPartExamined)
    print('Exposure -' ,Data.Exposure)
    print('FilterType - ' ,Data.FilterType)
    print('InstitutionAddress -',Data.InstitutionAddress)
    print('KVP -'  ,Data.KVP)
    print('ManufacturerModelName -' ,Data.ManufacturerModelName)
   

    DFdictionary = {}
    if cPID.get()==1:
        print('PatientID ON')
        DFdictionary['PatientID'] = [Data.PatientID]

    df = pd.DataFrame ({
        
        
        
                        'PatientID ': [Data.PatientID],

        })


     #Asking the user to choose output location   
    class filelocaoutput:
       def SaveDatatoxlsx():
           pass
       filelocaloutput = filedialog.asksaveasfilename(defaultextension = 'xlsx')
       df.to_excel (filelocaloutput)



  


       
root = Tk()
root.geometry("600x500")
Scallbtn = ttk.Button(root , text = 'Select All')
Scallbtn.place(y=450 , x=430)
Run_btn = ttk.Button(root, text='Run',command = filelocainput)
Run_btn.place(y=450, x=520)
# MainWindowbg = PhotoImage(file="BG.png")
# MainWindowbg_label = Label(root , image=MainWindowbg)
# MainWindowbg_label.place(y=0,x=0 , relwidth =1 , relheight=1)


     

cPID = IntVar()
CheckBoxPID = Checkbutton(root , 
                            text = 'PatientID',variable = cPID,
                            onvalue = 1 , offvalue = 0 , command=cPID,
                       )
CheckBoxPID.place(y=20 , x=20)






root.mainloop()



Aucun commentaire:

Enregistrer un commentaire