私は大学のクラスのプロジェクトに取り組んでおり、何かのために tkinker GUI を作成しようとしていますが、その中で適切な位置を得るのに問題があります。
ここに私のコードがあります:
from tkinter import *
from sys import exit
def button_func():
print("Test")
class TestClient(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.pack()
w = Listbox(width=20,height=24)
w.insert(1,"WoW")
w.pack(side=LEFT)
w = Text(width=60)
w.pack(side=LEFT)
w = Listbox(width=20,height=24)
w.insert(1,"Hi")
w.pack(side=RIGHT)
w = Button(self, text="Start", width=10,padx=10,pady=10, command=button_func)
w.pack(side=LEFT)
w = Button(self, text="Change Room", width=10,padx=10,pady=10, command=button_func)
w.pack(side=LEFT)
w = Button(self, text="Change Room", width=10,padx=10,pady=10, command=button_func)
w.pack(side=LEFT)
w = Button(self, text="FIGHT", width=10,padx=10,pady=10, command=button_func)
w.pack(side=LEFT)
w = Button(self, text="PvP FIGHT", width=10,padx=10,pady=10, command=button_func)
w.pack(side=LEFT)
w = Button(self, text="Loot", width=10,padx=10,pady=10, command=button_func)
w.pack(side=LEFT)
w = Button(self, text="Leave", width=10,padx=10,pady=10, command=button_func)
w.pack(side=LEFT)
stats = Listbox(width= 20)
stats.insert(1,"health:")
stats.pack(side=BOTTOM)
root = Tk()
root.title = "Test program"
tw = TestClient(root)
root.mainloop()
問題は、トップ ボタンをテキスト ウィジェットとリスト ボックス ウィジェットの下に配置し、ヘルスとラベル付けされたリスト ボックスをその下に配置することです。それらを上下にパッキングしようとしましたが、どちらも機能せず、解決策が見つかりません。グーグルまたはここで、これについてどうすればよいか知っている人はいますか?
PS インデントが悪い場合は申し訳ありませんが、初めてここで、インデントを台無しにせずにコードを貼り付ける方法がわかりませんでした。
大まかなアイデアについては、以下を参照してください。
from tkinter import *
from sys import exit
def button_func():
print("Test")
class TestClient(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.pack()
for n in range(3):
self.grid_rowconfigure(n, weight=1)
for n in range(8):
self.grid_columnconfigure(n, weight=1)
lb1 = Listbox(self, width=20,height=24)
lb1.insert(1,"WoW")
lb1.grid(row=0, column=0, columnspan=2, sticky='news')
t1 = Text(self, width=60)
t1.grid(row=0, column=3, columnspan=3)
lb2 = Listbox(self, width=20,height=24)
lb2.insert(1,"Hi")
lb2.grid(row=0, column=6, columnspan=2, sticky='news')
b1 = Button(self, text="Start", width=10,padx=10,pady=10, command=button_func)
b1.grid(row=1, column=0)
b2 = Button(self, text="Change Room", width=10,padx=10,pady=10, command=button_func)
b2.grid(row=1, column=1)
b3 = Button(self, text="Change Room", width=10,padx=10,pady=10, command=button_func)
b3.grid(row=1, column=3)
b3 = Button(self, text="FIGHT", width=10,padx=10,pady=10, command=button_func)
b3.grid(row=1, column=4)
b4 = Button(self, text="PvP FIGHT", width=10,padx=10,pady=10, command=button_func)
b4.grid(row=1, column=5)
b5 = Button(self, text="Loot", width=10,padx=10,pady=10, command=button_func)
b5.grid(row=1, column=6)
b6 = Button(self, text="Leave", width=10,padx=10,pady=10, command=button_func)
b6.grid(row=1, column=7)
stats = Listbox(self, width= 20)
stats.insert(1,"health:")
stats.grid(row=2, column=0, columnspan=8, sticky='news')
root = Tk()
root.title = "Test program"
tw = TestClient(root)
root.mainloop()
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加