Vahagn
Vahagn

Reputation: 4830

How to set the size of tk_messageBox?

I am using a tk_messageBox with a lage message, so I would like to configure the layout of that message dialog.

I am using tk_messageBox like this:

set status [tk_messageBox -type yesno -icon warning -message "Here goes a text with 50 words"]

How can I set the width and height of tk_messageBox here?

Maybe there are some better alternatives for tk_messageBox?

Upvotes: 4

Views: 7207

Answers (4)

Holger Jakobs
Holger Jakobs

Reputation: 1062

I use these settings, but haven't tested on other platforms beside X11

option add *Dialog.msg.wrapLength 10c 
option add *Dialog.dtl.wrapLength 10c

Of course you can try other sizes than 10c (which stands for 10 centimeters).

Upvotes: 0

Ben George
Ben George

Reputation: 76

.option_add may only work for linux operating systems, but you can control font, where the lines wrap, and the width of the box:

root.option_add('*Dialog.msg.font', 'Helvetica 24')
root.master.option_add('*Dialog.msg.width', 34)
root.master.option_add("*Dialog.msg.wrapLength", "6i")

(where "6i" is the length of the line in inches)

Upvotes: 1

user1908430
user1908430

Reputation: 61

Is this what you had in mind?

import Tkinter
import tkMessageBox 

window = Tkinter.Tk()
window.option_add('*Dialog.msg.width', 50)
tkMessageBox.showinfo("header", "Hello, World!") 

Upvotes: 3

Donal Fellows
Donal Fellows

Reputation: 137587

You can't set the size of a tk_messageBox (that's functionality which doesn't fit with the way those dialogs work on Windows and OSX). You can try putting some of the message into the -detail option, which usually uses a smaller font.

Or you can try looking in the file msgbox.tcl of your Tk installation for the Tcl code that implements the message box dialog on Unix/X11. Hint: on that platform only, tk_messageBox is really an alias for ::tk::MessageBox. The name of the widget created by that script depends on the -parent option, but if that's absent, it's .__tk__messagebox. Knowing that, you should be able to use clever event handling to configure the toplevel widget in question. But this is not a nice solution, and won't work on either Windows or OSX (when build for Aqua instead of X11).

Upvotes: 4

Related Questions