mmkw43
Posts: 666
Joined: Tue Dec 24, 2013 6:18 pm

Tkinter -- widgets on topmost layer?

Tue Nov 17, 2020 8:32 pm

How do you create a widget (a label in my case) that supersedes anything behind it (another label)? I want to put up a help screen with a "close" button, so it will just be there temporarily but I have no empty space to put it in.

Do I have to create a frame first? Or is there something I can do just to give my new label priority?

Stumped or I wouldn't ask -- thanks much.

scotty101
Posts: 4172
Joined: Fri Jun 08, 2012 6:03 pm

Re: Tkinter -- widgets on topmost layer?

Wed Nov 18, 2020 9:45 am

Difficult to advise you without an example but if you've used "grid" to layout the GUI you can just place your new widget on the same row/column and it will appear over the top of the existing one. You can then use ".destroy()" to remove it again.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

mmkw43
Posts: 666
Joined: Tue Dec 24, 2013 6:18 pm

Re: Tkinter -- widgets on topmost layer?

Wed Nov 18, 2020 5:00 pm

I'm using PLACE throughout.

Haven't looked into it yet but can frame "toplevel" or "raise" be of any value? Saw something regarding those used with frame.
Can't provide an example because I don't know how to do it. Simply placing another label on my screen puts the label behind my other widgets as I can see just segments of it.

mmkw43
Posts: 666
Joined: Tue Dec 24, 2013 6:18 pm

Re: Tkinter -- widgets on topmost layer?

Wed Nov 18, 2020 5:33 pm

MY BAD.

I forgot to put place.update() after my new frame (with my help text) and it pops up fine. Not the first time I forgot that. Works great now.

scotty101
Posts: 4172
Joined: Fri Jun 08, 2012 6:03 pm

Re: Tkinter -- widgets on topmost layer?

Thu Nov 19, 2020 8:56 am

You shouldn't have to use update. The tkinter mainloop should handle periodic updates.

Also, I would never use place....
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

mmkw43
Posts: 666
Joined: Tue Dec 24, 2013 6:18 pm

Re: Tkinter -- widgets on topmost layer?

Wed Dec 02, 2020 3:03 pm

Scotty --

Why shouldn't place be used? I only used it because I need very specific locations for 15 labels (and other widgets) in this program. And thanks for the tip about update. Fact is, there were certain widgets that only wouldn't appear unless I used it -- so, perhaps I'm doing something wrong.

For the fun of it (this is just a hobby), I'm going to go back and examine things closer. Works fine but it's the OCD in me.

scotty101
Posts: 4172
Joined: Fri Jun 08, 2012 6:03 pm

Re: Tkinter -- widgets on topmost layer?

Wed Dec 02, 2020 5:36 pm

Here are the reasons why I think place is a bad idea

1. Having to manually figure out the coordinates where I want things to be placed. PITA
2. Doesn't support changing the layout when the window is resized like pack/grid do. You'd have to move everything manually
3. Can often be confusing whether your coordinates are relative to the root window or one of the widgets below that, like if you put items inside a frame.
4. If I decide to add a new widget between two existing ones, with place I have to re-type all new coordinates to move the other widgets down/along
5. It isn't responsive to change in font sizes, if I make a font bigger, it might overlap with another widget

:mrgreen:

As I said in my first reply to you, the best way for us to help is if you share your code and explain what the problem is.
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

Return to “Graphics programming”