如何在 tkinter 中并排放置按钮并在小部件顶部填充 Y

问题描述

我正在尝试将小部件顶部的三个按钮并排对齐并填充“Y”和“X”,而不更改它们正下方的文本小部件的位置。我尝试使用那些 anchor=NW,N,NE 并排放置按钮,但它不起作用我不知道如何用英语告诉它,所以这是我得到的图像:

My application

这是我的代码:

root = Tk()        
                    


screen_x = int(root.winfo_screenwidth())
screen_y = int(root.winfo_screenheight()) - int(root.winfo_screenheight()) * int(9.1145833333) // 100



window_x = 512
window_y = 690 

posX = (screen_x // 2) - (window_x // 2)
posY = (screen_y // 2) - (window_y // 2)

geo = "{}x{}+{}+{}". format(window_x,window_y,posX,posY)

root.geometry(geo)
root.resizable(0,0)
root.title("StoryApp")
root.config(background="gray8")

photo2 = PhotoImage(file = "Newico.png")
root.iconphoto(False,photo2)

Btn1 = Button(root,text="Button1",command=passit,padx=5,pady=5,borderwidth=5,relief="sunken",activebackground="dark red",bg="gray15",fg="red")
Btn1.configure(height=1,width=6)
Btn1.pack(padx=10,side=TOP,anchor=NW,fill=Y)




Btn2 = Button(root,text="Button2",padx=2,fg="red")
Btn2.configure(height=1,width=6)
Btn2.pack(padx=10,anchor=N,fill=Y)

Btn3 = Button(root,text="Button3",fg="red")
Btn3.configure(height=1,width=6)
Btn3.pack(padx=10,anchor=NE,fill=Y)





DecodedTextBoxTitle = LabelFrame(root,text="Decoded code",height=260)
DecodedTextBoxTitle.config(background="gray8")
DecodedTextBoxTitle.config(foreground="red")
DecodedTextBoxTitle.pack(padx=10,fill="both",expand=True)

DecodedTextBox = Text(DecodedTextBoxTitle,wrap='none',undo=True,autoseparators=True,selectbackground="dark red")
DecodedTextBox.config(highlightbackground="gray15")
DecodedTextBox.config(foreground="red")
DecodedTextBox.config(highlightthickness=3)
DecodedTextBox.config(highlightcolor="dark red")
DecodedTextBox.config(background="gray15")
DecodedTextBox.pack(fill="both",expand=True)
DecodedTextBox.configure(state='normal')

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)