0

Apologies if this is a completely easy fix and I've just missed it. I am learning Python and I am trying to develop a GUI alongside my backend code using Tkinter. This is completely foreign to me and I have recently come across the problem that when I press my buttons there is a very small chance that it will make my window move behind all other open programs.

I am not entirely sure what is causing this but my guess is it stems somehow from one of two functions I have; one meant to minimise the main root window and the second to reveal it. However, these functions are not called in any place in my program that I would not expect them and the windows being minimised are not the root window (which my two functions act on).

I have both functions added below (hopefully, I am pretty new to SO) but if any additional code is needed I will supply it. I have quite a bit of code and everything else functions perfectly so I didn't want to post all my code is all.

There is no particular combination of button presses or buttons in particular which cause it, it appears to be any of them seemingly at random. It sends whatever window I have up to the taskbar.

def revealMenu():
    root.update()
    root.deiconify()


def hideMenu():
    root.withdraw()
kenos_x
  • 41
  • 6
  • Provide additional code. – K450 Nov 18 '21 at 08:57
  • What code in particular? I have 354 lines of code and I am very unsure what else would be relevant. No other code in my program affects window positioning or state on the screen except for where those two functions are called. – kenos_x Nov 18 '21 at 09:05
  • I accidentally fixed it myself but I am interested in how. I changed all Tk() instances to Toplevel() instances. I had forgotten to last time I edited the program. Any reason why this would've fixed it? – kenos_x Nov 18 '21 at 09:09
  • there should only be one root window i.e only one instance of `Tk()` in an Tkinter application. Other windows shlould be implemented as the toplevel widgets of the root. Having multiple root windows is like having multiple isolated application running at the same time and hence will not be able to interact with each other. – K450 Nov 18 '21 at 09:35
  • Ahh, that makes sense. I did change it because I had seen similar advice but hadn't thought anything of it until I did end up changing it. Thanks for your help! – kenos_x Nov 19 '21 at 10:03
  • Please provide enough code so others can better understand or reproduce the problem. – Community Nov 20 '21 at 12:23

0 Answers0