Grid within a frame?

前端 未结 2 910
北恋
北恋 2020-12-18 01:02

Is it possible to place a grid of buttons in Tkinter inside another frame?

I\'m wanting to create a tic-tac-toe like game and want to use the grid feature to put ga

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-18 01:39

    Figured out a way to do it finally:

    from Tkinter import * 
    
    root = Tk()
    
    f = Frame(root, bg = "orange", width = 500, height = 500)
    f.pack(side=LEFT, expand = 1)
    
    f3 = Frame(f, bg = "red", width = 500)
    f3.pack(side=LEFT, expand = 1, pady = 50, padx = 50)
    
    f2 = Frame(root, bg = "black", height=100, width = 100)
    f2.pack(side=LEFT, fill = Y)
    
    b = Button(f2, text = "test")
    b.pack()
    
    b = Button(f3, text = "1", bg = "red")
    b.grid(row=1, column=3)
    b2 = Button(f3, text = "2")
    b2.grid(row=1, column=4)
    b3 = Button(f3, text = "2")
    b3.grid(row=2, column=0)
    
    root.mainloop()
    

    Having the grid inside a frame inside a frame is a bit of a hack to get the padding around the grid working but it works so I'm happy.

提交回复
热议问题