答案 0 :(得分: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()
正在使用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()
剩下的几何管理器是place
,但是当调整GUI大小时,其使用有时会很复杂。
答案 1 :(得分:2)
简单地用于放置y坐标,并更改x坐标
b in a
from tkinter import *
root = Tk()
对于第二个按钮
Button(root, text='Submit', width=10, bg='blue', fg='white', command=database).place(x=70, y=130)