简体   繁体   English

Python tkinter:如何制作window中间的小部件?

[英]Python tkinter: how to make the widgets in the middle of window?

I'm new to TK.我是 TK 的新手。 How to make the scrlledText and buttons in the middle of the window.如何制作 window 中间的 scrlledText 和按钮。

I executed the code and got it like the picture below with the Green line, but I want the style to be like the red line.我执行了代码,得到了如下图的绿线,但我希望样式像红线一样。

Any idea?任何想法? Thanks.谢谢。

window= Tk()
window.geometry('500x500')
window.resizable(0,0)
window.title("Server")

msgText = scrolledtext.ScrolledText(window, width=50, height=10, font=("宋体", 10),wrap=WORD)
msgText.grid(row=0, column=0,padx = 20,pady = 10)
self.statusText = scrolledtext.ScrolledText(window, width=50, height=10, font=("宋体", 10),wrap=WORD)
statusText.grid(row=1, column=0,padx = 20,pady = 10)

openFileButton = Button(window, width = 15, text="选择文件", command=self.openFile)
openFileButton.grid(row=2, column=0, sticky=W)


sendButton = Button(window, text='发送文件', width = 15,command=self.sendFile)
sendButton.grid(row=2, column=1, sticky=E)

在此处输入图像描述

It appears all that you need to do is add columnspan=2 when adding the scrolledtext widgets to the display.看来您需要做的就是在将滚动文本小部件添加到显示时添加columnspan=2 However, it's impossible for me to know for certain since you didn't provide a proper [mcve].但是,由于您没有提供适当的 [mcve],因此我无法确定。

msgText.grid(row=0, column=0,padx = 20,pady = 10, columnspan=2)
statusText.grid(row=1, column=0,padx = 20,pady = 10, columnspan=2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM