我可以调整tkMessagebox创建的消息框的大小吗?

2024-04-26 19:09:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用固定宽度的tkMessagebox创建信息对话。我在tkMessagebox.showinfo函数中看不到任何可以处理此问题的选项。有什么办法吗?谢谢!


Tags: 函数信息宽度选项对话办法tkmessageboxshowinfo
0条回答
网友
1楼 · 发布于 2024-04-26 19:09:11

据我所知,您不能调整tkMessageBox的大小,但是如果您愿意投入精力,可以创建自定义对话框。

这个小脚本演示了它:

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

运行脚本时,您应该会看到一个主窗口出现,其中有两个按钮,按下其中一个按钮后,您将创建一个TopLevel窗口,该窗口可以按#Here指定的脚本所示调整大小。 这些顶级窗口就像标准窗口一样,可以调整大小并具有子窗口小部件。 另外,如果您试图将子窗口小部件打包或网格化到TopLevel窗口中,则需要使用.geometry而不是-width-height,如下所示:

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

希望我能帮上忙,在这里尝试阅读TopLevel小部件: http://effbot.org/tkinterbook/toplevel.htm

相关问题 更多 >