开发者

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?


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).


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!") 


.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)


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜