Closed Kamran496 closed 5 months ago
@Kamran496 Have you tried winfo_reqwidth()
and winfo_reqheight()
?
@Kamran496 Have you tried
winfo_reqwidth()
andwinfo_reqheight()
?
@Akascape Same result, at least for me.
@Kamran496 Remove this line:
print(f".geometry() -> {root.geometry()}")
@Akascape
Still same result.
Code
import customtkinter
root = customtkinter.CTk()
print(f".width() -> {root.winfo_reqwidth()}")
print(f".height() -> {root.winfo_reqheight()}\n")
width = 500
height = 500
root.geometry(f"{width}x{height}")
print(f".width() -> {root.winfo_reqwidth()}")
print(f".height() -> {root.winfo_reqheight()}")
Output
.width() -> 200
.height() -> 200
.width() -> 200
.height() -> 200
@Kamran496 Maybe you should call them after initialising the app. Like using .after method :
root.after(500, lambda: print(f".width() -> {root.winfo_width()}"))
@Akascape
Thank you for the solution. Using .after as you've described above does indeed produce the correct output.
Another way to get correct output is .update() before calling .geometry(), .winfo_height() or .winfo_width().
See below Comment.
Code
import customtkinter
root = customtkinter.CTk()
print(f".geometry() -> {root.geometry()}")
print(f".width() -> {root.winfo_reqwidth()}")
print(f".height() -> {root.winfo_reqheight()}\n")
width = 500
height = 500
root.geometry(f"{width}x{height}")
root.update()
print(f".geometry() -> {root.geometry()}")
print(f".width() -> {root.winfo_width()}")
print(f".height() -> {root.winfo_height()}")
Output
.geometry() -> 200x200+208+208
.width() -> 200
.height() -> 200
.geometry() -> 500x500+208+208
.width() -> 500
.height() -> 500
Code:
Output