2

固定幅の tkMessagebox で情報ダイアログを作成したい。これを処理できる tkMessagebox.showinfo 関数のオプションは見当たりませんでした。何か方法はありますか?ありがとう!

4

2 に答える 2

2

私が知る限り、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()

スクリプトを実行すると、2 つのボタンを備えたマスター ウィンドウが表示されます。ボタンの 1 つを押すと、 でTopLevel指定されたスクリプトに示されているように、サイズを変更できるウィンドウが作成され#Hereます。これらの最上位ウィンドウは、標準のウィンドウと同じように機能し、サイズを変更したり、子ウィジェットを作成したりできます。また、子ウィジェットをウィンドウにパックまたはグリッドしようとしている場合は、 notまたは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

于 2015-02-04T21:00:35.523 に答える