How to Change the position of MessageBox using Python Tkinter


Let us suppose that we want to create a dialogue box using tkinter. To create the dialogue box we can use the MessageBox library which contains several functions to quickly create dialogue types.

To adjust the position of the created Dialogue Box, we can use its “toplevel” property which basically gives the priority to the current box and keeps all the other processes in the backend.

It contains some other functions like title, message, and details. To change the position of the MessageBox widget, we will use geometry method.


#import the tkinter library

from tkinter import *

#define the messagebox function
def messagebox():

#toplevel function creates MessageBox dialog which appears on top of the screen
   top.title("Click Me")
   #Define the position of the MessageBox
   x_position = 600
   y_position = 400
   #Define the property of the messageBox
   l1=Label(top, text= "Hello! TutorialsPoint",bg= "green", fg=
"white",font=('Times New Roman', 24),height=50, width= 50).pack()

#Create an instance of the tkinter frame
#And resize the frame
win = Tk()
Button(win, text="Click Me", command=messagebox,



Running the above code will generate the following output window.

When you click the “Click Me” button, it will open the following dialogue box which can be positioned later.

Updated on 04-Mar-2021 13:58:35