1

The messagebox by default opens in the center of the screen:

enter image description here

But I would like it to open at the bottom right of the screen:

enter image description here

My original code:

from tkinter import Tk
from tkinter.messagebox import Message 
from _tkinter import TclError

TIME_TO_WAIT = 1000
root = Tk()
root.withdraw()
try:
    root.after(TIME_TO_WAIT, root.destroy) 
    Message(title="Visual Studio Code", message="New Match Found", master=root).show()
except TclError:
    pass

As per indications, I tried using root.geometry but realized that it doesn't work for messagebox, only for standard box:

root = Tk()
x = 1000
y = -1000
root.geometry(f'250x150+{x}+{y}')
root.withdraw()

# rest of code...

Prints dedicated to Claudio's answer (to help understand our debate):

enter image description here

enter image description here

Digital Farmer
  • 1,705
  • 5
  • 17
  • 67
  • how-to-set-the-position-of-a-messagebox-using-tkinter : https://stackoverflow.com/questions/53833172/how-to-set-the-position-of-a-messagebox-using-tkinter#53839951 – Claudio Jun 17 '22 at 19:33
  • Hi @Claudio , I don't have a box to be closed with the ```messagebox```, I only have the ```messagebox```. – Digital Farmer Jun 17 '22 at 20:02

1 Answers1

0

The code below works on my system displaying the message box in the right bottom corner of the display. The 'trick' is that the messagebox hoovers over the parent window, so the appropriate setting of root.geometry() causes it to appear where the root window is placed on the screen. You have found it out by yourself already, but the root.withdraw() prevented the expected placement of the messagebox:

from tkinter import Tk
from tkinter.messagebox import Message 

TIME_TO_WAIT = 3000

root = Tk()
root.geometry(f'100x100+{root.winfo_screenwidth()-100}+{root.winfo_screenheight()-100}')
root.after(TIME_TO_WAIT, root.destroy)
Message(title="Visual Studio Code", message="New Match Found", master=root).show()
Claudio
  • 7,474
  • 3
  • 18
  • 48
  • Hi @Claudio Unfortunately in my tests the parent box opens at the bottom but the messagebox keeps opening in the center of the screen. Even increasing the size of the parent box (to in theory fit the messagebox inside it, it keeps opening in the center of the screen). I'll keep trying to understand why! – Digital Farmer Jun 17 '22 at 20:32
  • If you don't post the relevant code it's hard to guess what goes wrong. From what you have posted up to now, the code above should be the solution. Does the code above open the messagebox where it should on your system? – Claudio Jun 17 '22 at 20:36
  • The relevant code is exactly your indication, that's why I didn't add it, here on my computer, the parent box appears in the lower right corner but the messagebox keeps opening in the center of the screen. – Digital Farmer Jun 17 '22 at 20:37
  • Which **parent box** ??? There is no parent box in your code ... Hmmm ... – Claudio Jun 17 '22 at 20:39
  • My comments are regarding your code, mine really only has a messagebox. I posted in my question a screenshot of my computer screen when running your code, as you can see, two boxes are opened, one in the lower right corner opens first and the messagebox opens later in the center of the screen. – Digital Farmer Jun 17 '22 at 20:48
  • |What happens when you run the code from the shell? You seem to run it from a code editor. – Claudio Jun 17 '22 at 20:56
  • I just added in my question the screen print when I run the python code directly from the file, it generates two boxes in the same way as when it runs in Visual Studio Code (first screen print). – Digital Farmer Jun 17 '22 at 21:02
  • You are on MS Windows which I don't have currently access to running Linux. Seems to be a platform related problem ... – Claudio Jun 17 '22 at 21:04
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/245705/discussion-between-claudio-and-digital-farmer). – Claudio Jun 17 '22 at 21:11