-
Hi, I been having an issue with a white flicker when creating a new window whilst using dark mode. If i use
I will get a quick white flash when opening the window. Example code
python version 3.12.4 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
@ageekhere
Modified version of your code: import customtkinter
def open_new_window():
def lock_and_fill_window():
# Create a CTk button with functionality inside the new window
new_window.resizable(False, False)
close_button1 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button2 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button3 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button4 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button5 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button6 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button7 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button8 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button9 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button10 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button1.pack()
close_button2.pack()
close_button3.pack()
close_button4.pack()
close_button5.pack()
close_button6.pack()
close_button7.pack()
close_button8.pack()
close_button9.pack()
close_button10.pack()
new_window = customtkinter.CTkToplevel(app)
new_window.grab_set()
new_window.title("New Window")
new_window.geometry("1000x800")
# Wait half miliseconds
new_window.after(500, lock_and_fill_window)
# Main CTk window
app = customtkinter.CTk()
app.geometry("1000x800")
customtkinter.set_appearance_mode("dark") # Set dark theme
# Main window button with command to open the new window
main_button = customtkinter.CTkButton(app, text="Open New Window", command=open_new_window)
main_button.pack()
# Start the main event loop
app.mainloop() Hope, it will be helpful. |
Beta Was this translation helpful? Give feedback.
-
Got it! Here is your solution: I closely inspected the problem and found that the issue persists because of internal overriding of Updated code: import customtkinter
from customtkinter import CTkToplevel
from customtkinter import get_appearance_mode
from tkinter import Toplevel
import ctypes, sys
def external_handle_for_titlebar(win: CTkToplevel):
color_mode = get_appearance_mode()
if sys.platform.startswith("win"):
if color_mode.lower() == "dark":
value = 1
elif color_mode.lower() == "light":
value = 0
else:
return
try:
hwnd = ctypes.windll.user32.GetParent(win.winfo_id())
DWMWA_USE_IMMERSIVE_DARK_MODE = 20
DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19
# try with DWMWA_USE_IMMERSIVE_DARK_MODE
if ctypes.windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE,
ctypes.byref(ctypes.c_int(value)),
ctypes.sizeof(ctypes.c_int(value))) != 0:
# try with DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20h1
ctypes.windll.dwmapi.DwmSetWindowAttribute(hwnd, DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1,
ctypes.byref(ctypes.c_int(value)),
ctypes.sizeof(ctypes.c_int(value)))
except Exception as err:
print(err)
finally:
win.lift()
def external_handle_for_resizable(toplevel: CTkToplevel):
# Create a CTk button with functionality inside the new window
Toplevel.resizable(toplevel, False, False)
external_handle_for_titlebar(toplevel)
def open_new_window():
def fill_window():
close_button1 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button2 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button3 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button4 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button5 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button6 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button7 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button8 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button9 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button10 = customtkinter.CTkButton(new_window, text="Close", command=new_window.destroy)
close_button1.pack()
close_button2.pack()
close_button3.pack()
close_button4.pack()
close_button5.pack()
close_button6.pack()
close_button7.pack()
close_button8.pack()
close_button9.pack()
close_button10.pack()
new_window = customtkinter.CTkToplevel(app)
new_window.grab_set()
new_window.title("New Window")
new_window.geometry("1000x800")
# Resizable operation using external handle.
external_handle_for_resizable(new_window)
fill_window()
# Main CTk window
app = customtkinter.CTk()
app.geometry("1000x800")
customtkinter.set_appearance_mode("dark") # Set dark theme
# Main window button with command to open the new window
main_button = customtkinter.CTkButton(app, text="Open New Window", command=open_new_window)
main_button.pack()
# Start the main event loop
app.mainloop() Let me know whether it is now helpful or not. |
Beta Was this translation helpful? Give feedback.
@ageekhere
Got it! Here is your solution:
I closely inspected the problem and found that the issue persists because of internal overriding of
.resizable()
function inCTkToplevel
class which delays in setting title bar color of the window, and not in setting background color only. So, let's define external handles for them.Updated code: