Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法将我的按钮放置到tkinter中指定的一侧_Python_Tkinter_Python 3.6 - Fatal编程技术网

Python 无法将我的按钮放置到tkinter中指定的一侧

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

我在Python3.6中使用tkinter,以便学习GUI编程。我试图创建一个按钮。当我尝试将我的按钮
打包到
左侧
右侧
顶部
底部
时,我没有得到输出,而
侧=顶部
用于帧命令。请帮助我。提前谢谢

         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()

一个仅仅是代码而没有解释的答案不是很有用。你能描述一下你是怎么解决这个问题的吗?否则,读者必须逐行、逐字符地将代码与原始代码进行比较,以查看您所做的更改。