如何在 tkinter python gui 框架的所有四个角放置四个按钮
how to put four buttons in all four corners of the frame in tkinter python gui
嘿,我是 tkinter gui 的新手,请帮助我添加四个按钮,每个角一个,这是我尝试过的,请 hjelp
from tkinter import *
root=Tk()
labelsub2i = Label(root, bg="red")
labelsub2i.place(relwidth=0.8, relheight=0.7, relx=0.1, rely=0.15)
#BUTTONS FOR OPTIONS
button1 = Button(labelsub2i, text="Aasdddddddddddddddddd").grid(row=1,column=1,sticky=W)
button2 = Button(labelsub2i, text="Bsdaaaaaaaaaaaaaaaasad").grid(row=1,column=6,sticky=E)
button3 = Button(labelsub2i, text="Cdsaaaaaaaaaaaaaaqsdaa").grid(row=3,column=1,sticky=W)
button4 = Button(labelsub2i, text="Dadsssssssssssssssssssss").grid(row=3,column=6,sticky=E)
root.mainloop()
so This is how it looks like right now
wanted to add buttons on those corners
P.s.- thank you
对于你的情况,你可以使用 place(...)
而不是 grid(...)
:
button1 = Button(labelsub2i, text="Aasdddddddddddddddddd")
button1.place(relx=0, rely=0, anchor='nw')
button2 = Button(labelsub2i, text="Bsdaaaaaaaaaaaaaaaasad")
button2.place(relx=1.0, rely=0, anchor='ne')
button3 = Button(labelsub2i, text="Cdsaaaaaaaaaaaaaaqsdaa")
button3.place(relx=0, rely=1.0, anchor='sw')
button4 = Button(labelsub2i, text="Dadsssssssssssssssssssss")
button4.place(relx=1.0, rely=1.0, anchor='se')
嘿,我是 tkinter gui 的新手,请帮助我添加四个按钮,每个角一个,这是我尝试过的,请 hjelp
from tkinter import *
root=Tk()
labelsub2i = Label(root, bg="red")
labelsub2i.place(relwidth=0.8, relheight=0.7, relx=0.1, rely=0.15)
#BUTTONS FOR OPTIONS
button1 = Button(labelsub2i, text="Aasdddddddddddddddddd").grid(row=1,column=1,sticky=W)
button2 = Button(labelsub2i, text="Bsdaaaaaaaaaaaaaaaasad").grid(row=1,column=6,sticky=E)
button3 = Button(labelsub2i, text="Cdsaaaaaaaaaaaaaaqsdaa").grid(row=3,column=1,sticky=W)
button4 = Button(labelsub2i, text="Dadsssssssssssssssssssss").grid(row=3,column=6,sticky=E)
root.mainloop()
so This is how it looks like right now
wanted to add buttons on those corners
P.s.- thank you
对于你的情况,你可以使用 place(...)
而不是 grid(...)
:
button1 = Button(labelsub2i, text="Aasdddddddddddddddddd")
button1.place(relx=0, rely=0, anchor='nw')
button2 = Button(labelsub2i, text="Bsdaaaaaaaaaaaaaaaasad")
button2.place(relx=1.0, rely=0, anchor='ne')
button3 = Button(labelsub2i, text="Cdsaaaaaaaaaaaaaaqsdaa")
button3.place(relx=0, rely=1.0, anchor='sw')
button4 = Button(labelsub2i, text="Dadsssssssssssssssssssss")
button4.place(relx=1.0, rely=1.0, anchor='se')