pythontkintercustomtkinter

Why are the customtkinter widgets interactable, yet not visible?


I'm trying to create a simple UI that enables the user to select a directory (in the context of this project the Download directory) and provides a button that launches the runtime logic.

Yet, when I launch the program, the window gets generated and the widgets are placed, they are just invisible.

I was able to confirm that they were also interactable by using the examplecode provided by the official customTkinter documentation (CustomTkinter Documentation):

import customtkinter

def button_callback():
  print("button clicked")

app = customtkinter.CTk()
app.geometry("400x150")

button = customtkinter.CTkButton(app, text="my button", command=button_callback)
button.pack(padx=20, pady=20)

app.mainloop()

By blindly clicking into the window I eventually found the invisible button in this instance and the console indeed gave the correct result.

I tried changing appearance modes and colors, but to no avail. This is the current code for the desired UI.

import os

import customtkinter as ctk
from tkinter import filedialog
from Organizer import Organizer

ctk.set_appearance_mode("light")
ctk.set_default_color_theme("blue")

class App(ctk.CTk):

  def __init__(self):
    super().__init__()

    self.organizer = None

    self.title("Download Organizer")
    self.geometry("500x300")

    self.columnconfigure(0, weight=1)
    self.columnconfigure(1, weight=1)
    self.columnconfigure(2, weight=1)
    self.rowconfigure(0, weight=1)

    self.entry_path = ctk.CTkEntry(self, width=300)
    self.entry_path.grid(row=0, column=0)

    self.button_browse = ctk.CTkButton(self, text="Browse Directory",
                                       command=self.select_download_folder)
    self.button_browse.grid(row=0, column=1)

    self.button_action = ctk.CTkButton(self, text="Submit",
                                       command=self.on_button_click)
    self.button_action.grid(row=0, column=2)

  def select_download_folder(self):
    folder_selected = filedialog.askdirectory(
      initialdir=os.path.expanduser("~/Downloads"))
    if folder_selected:
      self.entry_path.delete(0, ctk.END)
      self.entry_path.insert(0, folder_selected)
    self.organizer = Organizer(folder_selected)

  def on_button_click(self):
    if self.organizer is None:
      print("Please select a directory first.")
      return
    self.organizer.organize()

if __name__ == "__main__":
  app = App()
  app.mainloop()

Note that the Organizer module contains the runtime logic and has no impact on this problem, I just wanted to include it here already.

I coded this in the PyCharm IDE on a MacOS System, if that helps.


Solution

  • Yet, when I launch the program, the window gets generated and the widgets are placed, they are just invisible.

    You cannot used old version. Try Python 3.12.5. Or better wait for new Python 3.14.0 by October 10th, 2024.