Change the size of MessageBox - Tkinter - GeeksforGeeks

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.
showinfo():- To display some usual Informationshowwarning():- To display warning to the Usershowerror():- To display different type of Erroraskquestion():- to Ask Query to the User
showinfo():- To display some usual Information
showwarning():- To display warning to the User
showerror():- To display different type of Error
askquestion():- to Ask Query to the User
Example: 
Python3
# MessageBox Illustration of showinfo() function from tkinter import *from tkinter import messagebox # creating window objecttop = Tk() def Button_1():    messagebox.showinfo("Status",                        "Button-1 Pressed")     def Button_2():    messagebox.showinfo("Status",                        "Button-2 Pressed") # size for windowtop.geometry("100x100")B1 = Button(top, text = "Button-1",            command = Button_1)  B2 = Button(top, text = "Button-2",            command = Button_2)   B1.pack()B2.pack()top.mainloop()  
Output:
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.  
Python3
from tkinter import *  main = Tk() # variable for textstr_var = StringVar() # Message Functionlabel = Message( main, textvariable=str_var,                relief=RAISED )  # The size of the text determines# the size of the messageboxstr_var.set("You can't Change Your Profile Picture ")label.pack()main.mainloop()
Output:
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: 
Python3
from tkinter import *from tkinter import messagebox top = Tk() def helpfile(filetype):         if filetype==1:                 with open("read.txt") as f:                         # reading file            readme = f.read()                         # Display whole message            messagebox.showinfo(title="Title",                                message = str(readme)) # Driver codehelpfile(1)top.mainloop()
Output:
 
Akanksha_Rai
simmytarika5
sumitgumber28
ruhelaa48
Python-tkinter
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Python Dictionary
Read a file line by line in Python
Enumerate() in Python
Iterate over a list in Python
How to Install PIP on Windows ?
Different ways to create Pandas Dataframe
Python String | replace()
Create a Pandas DataFrame from Lists
Python program to convert a list to string
Reading and Writing to text files in Python