I have a class for a GUI with two radio buttons one to set save_to_excel to True and the other to False. However I wanted to add a loading screen using threading, but when I add that second class the save_to_excel variable no longer updates when I press the radio buttons... Does it have to do with the way its initialized or is threading breaking it?
class LoadingScreen:
def __init__(self, root):
self.root = root
self.root.title("Loading...")
self.root.geometry("300x100")
self.root.configure(bg="white")
self.label = tk.Label(self.root, text="Loading, please wait...", bg="white", fg="black")
self.label.pack(expand=True)
class DICOMExtractorApp:
def __init__(self, root):
try:
self.root = root
self.root.title("DICOM Info Extractor")
self.root.configure(bg="white")
# Initializing variables
self.save_to_excel = tk.BooleanVar(value=True) # Default to saving to Excel
self.folder_path = ""
self.output_path = ""
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)
def create_widgets(self):
try:
self.root.geometry("800x600")
self.root.resizable(False, False)
# Load Folder button
tk.Button(self.root, text="Load Folder", command=self.load_folder, bg="#B7DFF5").place(x=50, y=20, width=100, height=30)
# Output Location button
tk.Button(self.root, text="Output Location", command=self.set_output_location, bg="#B7DFF5").place(x=200, y=20, width=120, height=30)
# Radio buttons for saving options
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)
def main_app():
def initialize_app():
root = tk.Tk()
app = DICOMExtractorApp(root)
loading_root.destroy()
root.deiconify()
root.mainloop()
loading_root = tk.Tk()
loading_screen = LoadingScreen(loading_root)
loading_root.after(1000, initialize_app)
loading_root.mainloop()
if __name__ == "__main__":
main_app()
When the "save to text" radio button is selected it should set the save_to_excel to False, and when the "save to excel" button is selected it set it to True..
Removing the LoadingScreen class fixes the code and it now correctly updates the variable as expected.
Replaced with, to remove loading screen:
if __name__ == "__main__":
root = tk.Tk()
app = DICOMExtractorApp(root)
root.mainloop()
tk.Radiobuttonlines in? It looks like they're in theexceptblock ofDICOMExtractorApp.__init__(), but that doesn't make much sense.LoadingScreenandDICOMExtractor?LoadingScreenrun whileDICOMExtractorwas being initialized. I can try using theLoadingScreenas aTopLevelwindow