이 창에는 실제로 tk.Frame에서 상속 된 3 개의 프레임이 있습니다 (여기서는 차이가 없다고 생각합니다).
첫 번째 프레임은 3 개의 버튼이있는 상단에 있으며 프로그램의 후반부에 1 개가 더 추가됩니다. 두 번째 프레임은 3x3 레이아웃의 9 개 버튼으로 구성됩니다. 세 번째 프레임에는 레이블이 있습니다 (실제로 왼쪽에 하나씩, 오른쪽에 하나씩 두 개의 레이블이 필요합니다.)
내가 달성하고 싶은 것은 첫 번째 프레임을 그대로 유지하는 것입니다. 두 번째 프레임의 3x3 레이아웃은 중앙 (최소한 수평으로)에 있어야하고 레이블은 세 번째 프레임에 있어야하며 하나는 가장 왼쪽에 있고 다른 하나는 ( 아직 추가하지 않았습니다) 절대 권리.
I have observed that whenever I change the padx
(and even ipadx
) values for any button in first frame, it seems to change the position of that 3x3 layout. Like when I increase padx
for Stats Button, it slides both the 3x3 layout and bottom most label to the right. Which i feel like is weird because padding of something in a whole different frame altogether should not affect the layout of any other frame.
HERE IS THE MINIMUM REPRODUCIBLE EXAMPLE TO MAKE YOU UNDERSTAND THE ISSUE MORE
import tkinter as tk
class MenuBar(tk.Frame):
def __init__(self, root):
tk.Frame.__init__(self, root)
class StBar(tk.Frame):
def __init__(self, root):
tk.Frame.__init__(self, root)
class MidSpace(tk.Frame):
def __init__(self, root):
tk.Frame.__init__(self, root)
class MainApp:
def __init__(self, root):
self.root = root
self.StBar = StBar(self.root)
self.MenuBar = MenuBar(self.root)
self.MidSpace = MidSpace(self.root)
self.root.grid_rowconfigure(0, weight=3)
self.root.grid_rowconfigure(1, weight=55)
self.root.grid_rowconfigure(2, weight=2)
self.MenuBar.grid(row=0, column=0)
self.MidSpace.grid(row=1, column=0)
self.StBar.grid(row=2, column=0)
self.htpb = tk.Button(self.MenuBar, text='How To Play', width=14,
bg='#00f', fg='#fff')
self.htpb.grid(row=0, column=0, padx=10, ipady=5, sticky=tk.N + tk.S)
self.statb = tk.Button(self.MenuBar, text='Stats', width=14,
bg='#00f', fg='#fff')
self.statb.grid(row=0, column=1, padx=10, ipady=5, sticky=tk.N + tk.S)
self.resb = tk.Button(self.MenuBar, text='Results', width=14,
bg='#00f', fg='#fff')
self.resb.grid(row=0, column=2, padx=10, ipady=5, sticky=tk.N + tk.S)
self.stLabel = tk.Label(self.StBar,
text='Some single line text here', bg='#00f',
fg='#fff', font=('roboto', 13))
self.stLabel.pack(anchor=tk.W)
self.b1 = tk.Button(self.MidSpace, text=' ',
bg='#da5', fg='#250038',
font=('roboto', 20), width=2, height=1)
self.b2 = tk.Button(self.MidSpace, text=' ',
bg='#745', fg='#380601',
font=('roboto', 20), width=2, height=1)
self.b3 = tk.Button(self.MidSpace, text=' ',
bg='#da5', fg='#250038',
font=('roboto', 20), width=2, height=1)
self.b4 = tk.Button(self.MidSpace, text=' ',
bg='#745', fg='#380601',
font=('roboto', 20), width=2, height=1)
self.b5 = tk.Button(self.MidSpace, text=' ',
bg='#da5', fg='#250038',
font=('roboto', 20), width=2, height=1)
self.b6 = tk.Button(self.MidSpace, text=' ',
bg='#745', fg='#380601',
font=('roboto', 20), width=2, height=1)
self.b7 = tk.Button(self.MidSpace, text=' ',
bg='#da5', fg='#250038',
font=('roboto', 20), width=2, height=1)
self.b8 = tk.Button(self.MidSpace, text=' ',
bg='#745', fg='#380601',
font=('roboto', 20), width=2, height=1)
self.b9 = tk.Button(self.MidSpace, text=' ',
bg='#da5', fg='#250038',
font=('roboto', 20), width=2, height=1)
self.b1.grid(row=0, column=0, ipadx=40, ipady=40)
self.b2.grid(row=0, column=1, ipadx=40, ipady=40)
self.b3.grid(row=0, column=2, ipadx=40, ipady=40)
self.b4.grid(row=1, column=0, ipadx=40, ipady=40)
self.b5.grid(row=1, column=1, ipadx=40, ipady=40)
self.b6.grid(row=1, column=2, ipadx=40, ipady=40)
self.b7.grid(row=2, column=0, ipadx=40, ipady=40)
self.b8.grid(row=2, column=1, ipadx=40, ipady=40)
self.b9.grid(row=2, column=2, ipadx=40, ipady=40)
if __name__ == '__main__':
win = tk.Tk()
win.geometry('1360x710')
win.title('TicTacToe - pssolanki')
win.wm_geometry("+0+0")
win.configure(bg='#fff')
MainApp(win)
win.mainloop()
If ya need to know anything else either let me know or check the code at Github Repository
Any help or suggestion is appreciated. You can also suggest a better title for the question 'cause I couldn't think of anything better.
Thank YOU :)
그 이유는 세 프레임이 모두 단일 열에 있기 때문입니다. 열은 격자에서 균일 한 너비를 갖기 때문에 상단 프레임을 넓게 만들면 전체 열이 넓어지고 두 번째 및 세 번째 프레임이 나타나는 방식에 영향을줍니다.
내 조언은 pack
세 개의 최상위 프레임에 사용하는 것입니다. 나는 MenuBar
상단을 StBar
따라, 하단을 따라, 그리고 MidSpace
중간에 포장 할 것 입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다