2017-03-15 8 views
0

私は何かのためにtkinker GUIを作ろうと試みているが、大学でのクラスのプロジェクトに取り組んでいるが、その中で正しい位置づけを得るのに問題がある。ここで .packをtkinkerに入れてウィジェットを正しく配置する方法は?

が私のコードです:

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

問題は、私はそれを下回ると、トップボタンは、テキストやリストボックスウィジェットやリストボックスラベルの健康を下回るようにしたいということです、I'vは、それらを梱包しようとしましたトップとボトムは、どちらも仕事と私はgoogleやここで、私はこれについて行くだろうどのように知っているのですか?

P.S.申し訳ありませんインデントが悪い場合は、ここで初めてとインデントを台無しにすることなく、コードを貼り付ける方法がわかりませんでした。

+0

私は、この場合には、グリッドではなく、パックを使用してreccomend。あなたはそれを試しましたか?あなたはまたあなたのすべてのウィジェットのために 'w'識別子を使用しています。 –

+0

ああ、それは私が前にグリッドを使ってみたのですが、グリッドを使用しようとしましたが、テキストボックスとリストボックスの1つしか表示されませんでした。 。 – Will

+0

self.grid_rowconfigureとself.grid_columnconfigureを見てください。あなたが言ったことから、私はあなたが各列/行に与えられた重みを与えられないことを推測しています。 :) –

答えて

0

は目安については、以下を参照してください:

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() 
関連する問題