Can I adjust the size of message box created by tkMessagebox?

故事扮演 提交于 2019-12-13 01:19:45

问题


I want to create information dialogue with tkMessagebox with a fixed width. I didn't see any options in the tkMessagebox.showinfo function that can handle this. Is there any way? Thanks!


回答1:


As far as I'm aware you can't resize the tkMessageBox, but if you're willing to put in the effort you can create custom dialogs.

This little script demonstrates it:

from tkinter import * #If you get an error here, try Tkinter not tkinter

def Dialog1Display():
    Dialog1 = Toplevel(height=100, width=100) #Here

def Dialog2Display():
    Dialog2 = Toplevel(height=1000, width=1000) #Here

master=Tk()

Button1 = Button(master, text="Small", command=Dialog1Display)
Button2 = Button(master, text="Big", command=Dialog2Display)

Button1.pack()
Button2.pack()
master.mainloop()

When you run the script you should see a master window appear, with two buttons, upon pressing one of the buttons you'll create a TopLevel window which can be resized as is shown in the script designated by#Here. These top level windows act just like standard windows and can be resized and have child widgets. Also if you're trying to pack or grid child widgets into the TopLevel window then you'll need to use .geometry not -width or -height, this would go something like this:

from tkinter import *

def Dialog1Display():
    Dialog1 = Toplevel()
    Dialog1.geometry("100x100")

def Dialog2Display():
    Dialog2 = Toplevel()
    Dialog2.geometry("1000x1000")

master=Tk()

Button1 = Button(master, text="Small", command=Dialog1Display)
Button2 = Button(master, text="Big", command=Dialog2Display)

Button1.pack()
Button2.pack()
master.mainloop()

Hope I helped, try reading up on the TopLevel widget here: http://effbot.org/tkinterbook/toplevel.htm



来源:https://stackoverflow.com/questions/28328543/can-i-adjust-the-size-of-message-box-created-by-tkmessagebox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!