CustomTkinter
CustomTkinter copied to clipboard
withdraw() doesn't work on main program at start.
When being used to hide the main window, the main window doesn't become hidden. Although, later when used through a function on a top level window, it disappears as it should.
Which platform are you using and which python version?
Using windows, python 3.7.9 and running it in Thonny
I just came here to start this same issue. I'm using Python 3.10 on Windows 11, customtkinter v4.5.9.
If you run this, with tkinter, the window never pops up (as it should):
import tkinter as tk
root = tk.Tk()
root.withdraw()
root.mainloop()
If you run this, with customtkinter, the window always pops up (it shouldn't):
import customtkinter
root = customtkinter.CTk()
root.withdraw()
root.mainloop()
Using root.after(0,root.withdraw) (instead of root.withdraw()) with tkinter also works pretty normally (the window doesn't even flash). With customtkinter it does hide the window but it flashes rapidly.
This customtkinter behavior leads to another problem that wouldn't happen if it did hide:
import customtkinter
root = customtkinter.CTk()
root.withdraw()
root.set_scaling(1, 1, 1)
root.geometry("800x600")
root.deiconify()
root.mainloop()
When resizing the window after calling set_scaling the user sees the window changing size (it should pop up already in the correct size, as tkinter normally does). I realized that calling set_scaling after geometry makes the window pop up in the correct size, but that seems to create other problems:
def _place_window_on_screen(self):
self.update()
# self.withdraw()
width = self.winfo_reqwidth()
height = self.winfo_reqheight()
offset = {
"x": int(0.5 * self.winfo_screenwidth() - width // 2),
"y": int(0.5 * self.winfo_screenheight() - height // 2 - 20),
}
print(width, height, offset)
self.geometry(f"{width}x{height}+{offset['x']}+{offset['y']}")
# self.geometry("698x434+611+303")
If set_scaling is called just before this function, the user will see the window resizing but it will be in the middle of the screen. If set_scaling is called right after this function, the window will pop up already in the correct size but not in the middle of the screen. The same goes if I print the calculated geometry input, hardcode it and run those two situations again.
I tried to look a bit into your implementation, but most of it is beyond the scope of my abilities and I can't really contribute much.
Doing some tests, I realized root.geometry("+400+300") works in tkinter but raises a ValueError in customtkinter.
…\customtkinter\windows\ctk_tk.py", line 137, in geometry
numbers = list(map(int, re.split(r"[x+-]", geometry_string))) # split geometry string into list of numbers
ValueError: invalid literal for int() with base 10: ''
Python 3.8 https://github.com/TomSchimansky/CustomTkinter/issues/101#issuecomment-1134194964
https://github.com/TomSchimansky/CustomTkinter/issues/206#issuecomment-1165882822
Should work now with version 4.5.11.