Setting the position on a button in Python?

后端 未结 3 654
南方客
南方客 2020-12-09 10:32

I just wrote a code that creates a window (using TKinter) and displays one working button.

b = Button(master, text=\"get\", width=10, command=callback)
         


        
3条回答
  •  醉酒成梦
    2020-12-09 11:09

    astynax is right. To follow the example you gave:

    MyButton1 = Button(master, text="BUTTON1", width=10, command=callback)
    MyButton1.grid(row=0, column=0)
    
    MyButton2 = Button(master, text="BUTTON2", width=10, command=callback)
    MyButton2.grid(row=1, column=0)
    
    MyButton3 = Button(master, text="BUTTON3", width=10, command=callback)
    MyButton3.grid(row=2, column=0)
    

    Should create 3 row of buttons. Using grid is a lot better than using pack. However, if you use grid on one button and pack on another it will not work and you will get an error.

提交回复
热议问题