.grid()ボタンが多いのでGUIを作っています。Frameこれらを画面の上部 ( frameone)のインタラクティブに配置frametwoし、ユーザーが押したボタンに基づいてメッセージを出力する場所を下部に配置しました。文脈上、これは戦艦ゲームです。しかし、私が作ってそこframetwoに入れるとlistbox、リストボックスはテキストが収まるようにサイズ変更されます。labelより多くの s が入力されるたびにウィンドウのサイズを変更する必要はありません。これが実際の例です:
from tkinter import *
import tkinter as tk
window = Tk()
window.title("Window")
window.geometry('150x350') #I wanted the demonstration to work for you.
def addline(): #Adding sample text
Label(listbox, text='this is text').grid(sticky=N+W)
frameone = Frame(window, height=10, width=10)
frameone.grid(sticky=N) #The top where the button goes...
Label(frameone, bg='yellow', text='This is frameone\n\n\n').grid(row=0, column=0)
#The yellow here is where all the buttons go...
addtext = Button(frameone, text = 'Add line:', command=addline)
addtext.grid(column=0,row=1) #Button to add text...
frametwo = Frame(window, bg='red', height=10, width=10)
frametwo.grid(sticky=W)
listbox = Listbox(frametwo)
listbox.grid(sticky=W, pady=3, padx=3) #This is the listbox that is wrongly resizing.
scrolltwo = Scrollbar(window, orient=HORIZONTAL)
scrolltwo.configure(command=listbox.yview)
scrolltwo.grid(sticky=S+E) #I got lazy, I will put this on the side w/rowspan etc.
window.mainloop()
これが繰り返しの質問であるか、何らかの形で非常に明白である場合は、お詫び申し上げます。また、申し訳ありませんが、私の GUI はひどいものです...この方法が機能しない理由がわかりません。解決策を探している間に、私が見つけたのは、いくつかの非常に良い説明と.grid、そうでないときにリストのサイズを変更する方法だけでした。すべてが役に立ちます、ありがとう。