如何与tkinter并排放置多个小部件?

Rem*_*ida 2 python tkinter python-3.x

默认情况下,按下tkinter按钮后,它将自动将下一个按钮放在另一行上
如何阻止这种情况的发生?
我想做这样的事情:
在此处输入图片说明

Reb*_*que 5

您必须为此使用几何管理器之一:

在这里grid

将tkinter导入为tk

root = tk.Tk()

b1 = tk.Button(root, text='b1')
b2 = tk.Button(root, text='b2')
b1.grid(column=0, row=0)   # grid dynamically divides the space in a grid
b2.grid(column=1, row=0)   # and arranges widgets accordingly
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

那里使用pack

import tkinter as tk

root = tk.Tk()

b1 = tk.Button(root, text='b1')
b2 = tk.Button(root, text='b2')
b1.pack(side=tk.LEFT)      # pack starts packing widgets on the left 
b2.pack(side=tk.LEFT)      # and keeps packing them to the next place available on the left
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

剩下的几何管理器是place,但是在调整GUI大小时,有时使用起来很复杂。