![](/img/trans.png)
[英]How to make the tkinter window responsive with the widgets placed using pack() method in Tkinter Python?
[英]Python tkinter: how to make the widgets in the middle of window?
我是 TK 的新手。 如何制作 window 中间的 scrlledText 和按钮。
我执行了代码,得到了如下图的绿线,但我希望样式像红线一样。
任何想法? 谢谢。
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)
看来您需要做的就是在将滚动文本小部件添加到显示时添加columnspan=2
。 但是,由于您没有提供适当的 [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.