Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Change the size of MessageBox – Tkinter

  • Last Updated : 21 Aug, 2021

Python have many libraries for GUI. Tkinter is one of the libraries that provides a Graphical user interface. For the Short Message, we can use the MessageBox Library. It has many functions for the effective interface. In this MessageBox library provide different type of functions to Display Message Box.

  1. showinfo():- To display some usual Information
  2. showwarning():- To display warning to the User
  3. showerror():- To display different type of Error
  4. askquestion():- to Ask Query to the User


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course


# MessageBox Illustration of showinfo() function
from tkinter import *
from tkinter import messagebox
# creating window object
top = Tk()
def Button_1():
                        "Button-1 Pressed")
def Button_2():
                        "Button-2 Pressed")
# size for window
B1 = Button(top, text = "Button-1",
            command = Button_1)  
B2 = Button(top, text = "Button-2",
            command = Button_2)  



By default, the size of the message box is Fix. We can’t change the size of that Message Box. Different Boxes have different sizes. However, we can use Different alternative methods for this purpose  

  • Message Widget
  • By Changing ReadMe File

1. Message Widget 
MessageBox library doesn’t provide the functions to change the configuration of the box. We can use the other function. The message can also be used to display the information. The size of the message is the size of the window so that we can set the size of the message by geometry, pack.  


from tkinter import *
main = Tk()
# variable for text
str_var = StringVar()
# Message Function
label = Message( main, textvariable=str_var,
                relief=RAISED )
# The size of the text determines
# the size of the messagebox
str_var.set("You can't Change Your Profile Picture ")



2. By Changing ReadMe File 
This is another alternative option of the Message Box. In this, We are Opening the file readme.txt the length of the content of the readme file determines the size of the messagebox.

Input File: 



from tkinter import *
from tkinter import messagebox
top = Tk()
def helpfile(filetype):
    if filetype==1:
        with open("read.txt") as f:
            # reading file
            readme =
            # Display whole message
                                message = str(readme))
# Driver code




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!