I am computing the width of a Toplevel
window based on the title and the text inside. For the text inside, there is no problem, since I am the one who set the font
property of the text and so I can use the measure
method of the font. In contrast, there does not seem to be a way to set the font of the title. But how can I at least get the font that is being used?
Asked
Active
Viewed 78 times
0

AlwaysLearning
- 7,257
- 4
- 33
- 68
-
What do it this way? You can just measure top level with `widget.winfo_height() and widget.winfo_width()` – Mike - SMT Jun 13 '17 at 22:56
-
@SierraMountainTech I am measuring the text in order to set the size of `Toplevel` accordingly, i.e. to fit the text that is going to be displayed in it. – AlwaysLearning Jun 13 '17 at 23:02
-
Ah ok. It is a little different to worry about the window frame text but would be good to know if its possible. I will do some research. – Mike - SMT Jun 13 '17 at 23:03
-
You may not be able to get info about the title bar however you can disable the title bar with `overrideredirect()` and then make your own title bar with a label or a frame. This should allow you to set any font you wish and be able to calc your width. – Mike - SMT Jun 13 '17 at 23:17
-
@SierraMountainTech Are you really saying that there is no easy way to make sure that `Toplevel` is wide enough to contain its title? – AlwaysLearning Jun 14 '17 at 08:29
1 Answers
0
Tkinter does not provide a way to get at information about the decorations added by the window manager or os. You will have to find some platform-specific method of getting that information.

Bryan Oakley
- 370,779
- 53
- 539
- 685
-
Isn't there an easy way to make sure that `Toplevel` is wide enough to contain its title? – AlwaysLearning Jun 14 '17 at 08:30
-
-
This is hard to believe. I mean, that's just shameful. Isn't that a very basic requirement? Note that I posted this as a question: https://stackoverflow.com/q/44541189/2725810 – AlwaysLearning Jun 14 '17 at 10:48