I have a GUI with two radio buttons in a class, the first radio button using tkinter is meant to set the variable save_to_excel to be True while the second one should be false, this is meant for the user to determine if they want to save the info as an excel worksheet or text document. I have an older version of the code that works and correctly updates the variable however something must have changed with the new version that doesn’t update it correctly.
Current Code (not working):
class DICOMExtractorApp:
def __init__(self, root):
try:
self.root = root
self.root.title("DICOM Info Extractor")
self.root.configure(bg="white")
# Initializing variables
self.folder_path = ""
self.output_path = ""
self.save_to_excel = tk.BooleanVar(value=True) # Default to saving to Excel
self.dicom_tags = {}
self.default_tags = {
"Filename": "filename",
"Acquisition Date": (0x0008, 0x0022),
"Manufacturer": (0x0008, 0x0070),
"Study Description": (0x0008, 0x1030),
"Instance Number": (0x0020, 0x0013),
"Series Description": (0x0008, 0x103E),
"Acquisition Time": (0x0008, 0x0032),
"Modality": (0x0008, 0x0060),
"Station Name": (0x0008, 0x1010)
}
self.selected_tags = {tag: tk.BooleanVar(value=True) for tag in self.default_tags}
self.tags_per_page = 10
self.current_page = 0
self.create_widgets()
except Exception as e:
self.log_error(e)
...
tk.Radiobutton(self.root, text="Save to Excel", variable=self.save_to_excel, value=True, bg="white", command=self.print_save_option).place(x=350, y=20)
tk.Radiobutton(self.root, text="Save to Text", variable=self.save_to_excel, value=False, bg="white", command=self.print_save_option).place(x=460, y=20)
Old Code:
class DICOMExtractorApp:
def __init__(self, root):
self.root = root
self.root.title("DICOM Info Extractor")
self.root.configure(bg="white")
self.folder_path = ""
self.output_path = ""
self.save_to_excel = tk.BooleanVar(value=True)
self.dicom_tags = self.load_dicom_tags()
self.default_tags = {
"Filename": "filename",
"Acquisition Date": (0x0008, 0x0022),
"Manufacturer": (0x0008, 0x0070),
"Study Description": (0x0008, 0x1030),
"Instance Number": (0x0020, 0x0013)
}
self.selected_tags = {tag: tk.BooleanVar() for tag in self.default_tags}
self.create_widgets()
...
tk.Radiobutton(self.root, text="Save to Excel", variable=self.save_to_excel, value=True, bg="white",command=self.print_save_option).place(x=350, y=20)
tk.Radiobutton(self.root, text="Save to Text", variable=self.save_to_excel, value=False, bg="white",command=self.print_save_option).place(x=460, y=20)
I expect the output to print False when I select ‘save to text’ radio button and True when I select ‘save to excel’ radiobutton…
usherא is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.