我可以调整tkMessagebox创建的消息框的大小吗? [英] Can I adjust the size of message box created by tkMessagebox?

查看:503
本文介绍了我可以调整tkMessagebox创建的消息框的大小吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

据我所知,您无法调整tkMessageBox的大小,但如果您愿意付出努力,则可以创建自定义对话框./p>

这个小脚本演示了它:

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

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!

解决方案

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

这篇关于我可以调整tkMessagebox创建的消息框的大小吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆