您必须为此使用几何管理器之一:
在这里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大小时,有时使用起来很复杂。