Python 无法将我的按钮放置到tkinter中指定的一侧
我在Python3.6中使用tkinter,以便学习GUI编程。我试图创建一个按钮。当我尝试将我的按钮Python 无法将我的按钮放置到tkinter中指定的一侧,python,tkinter,python-3.6,Python,Tkinter,Python 3.6,我在Python3.6中使用tkinter,以便学习GUI编程。我试图创建一个按钮。当我尝试将我的按钮打包到左侧、右侧、顶部或底部时,我没有得到输出,而侧=顶部用于帧命令。请帮助我。提前谢谢 from tkinter import * import tkinter as tk root = tk.Tk() topframe = Frame(root) topframe.pack() bot
打包到左侧
、右侧
、顶部
或底部
时,我没有得到输出,而侧=顶部
用于帧命令。请帮助我。提前谢谢
from tkinter import *
import tkinter as tk
root = tk.Tk()
topframe = Frame(root)
topframe.pack()
bottomframe = Frame(root)
bottomframe.pack(side=BOTTOM)
button1 = Button(topframe, text="helo boys", fg="green")
button1.pack()
button2 = Button(topframe, text="how are you", fg="red")
button2.pack(side=LEFT)
button3 = Button(bottomframe, text="we are fine", fg="blue")
button3.pack(side=RIGHT)
root.mainloop()
您需要将两个按钮都打包到顶框的左侧:
import tkinter as tk
if __name__ == '__main__':
root = tk.Tk()
topframe = tk.Frame(root)
topframe.pack()
bottomframe = tk.Frame(root)
bottomframe.pack(side=tk.BOTTOM)
button1 = tk.Button(topframe, text="hello boys", fg="green")
button1.pack(side=tk.LEFT)
button2 = tk.Button(topframe, text="how are you", fg="red")
button2.pack(side=tk.LEFT)
button3 = tk.Button(bottomframe, text="we are fine", fg="blue")
button3.pack(side=tk.RIGHT)
root.mainloop()
button3.pack(side=tk.RIGHT)
与button3.pack()
具有相同的效果,因为此元素是bottomframe
中唯一的小部件
如果name='main':
root = tk.Tk()
topframe = tk.Frame(root)
topframe.pack()
bottomframe = tk.Frame(root)
bottomframe.pack(side=tk.BOTTOM)
button1 = tk.Button(topframe, text="hello boys", fg="green").place(x=140, y=380)
button2 = tk.Button(topframe, text="how are you", fg="red").place(x=140, y=380)
button3 = tk.Button(bottomframe, text="we are fine", fg="blue").place(x=140, y=380)
root.mainloop()
一个仅仅是代码而没有解释的答案不是很有用。你能描述一下你是怎么解决这个问题的吗?否则,读者必须逐行、逐字符地将代码与原始代码进行比较,以查看您所做的更改。