简体   繁体   English

[Tkinter]使用“ place”方法放置文本时,我无法将文本插入“文本”小部件中,也无法对其进行编辑

[英][Tkinter]I can't insert text into a Text widget when I use 'place' method to place it, and I also can't edit it

from tkinter import *

root = Tk()

# frame = Frame(root, height = 300, width = 500)
text = Text(root,width = 15)

# frame.pack()
# text.pack()
text.insert(END,'testwsetsetsetsets')
text.place(rely = 0, relx = 0.5, anchor = 'center')

mainloop()

在此处输入图片说明

There should be a text, but it din't, and I also can't edit it.I can't iuput any word into it. 应该有一个文本,但是不是,我也不能编辑它,我不能将任何单词输入其中。

This is due to the combination of options rely=0 and anchor='center' . 这是由于选项rely=0anchor='center'的组合所致。 The center of your text widget is at the top of your window so you cannot see the top half (including the inserted text). 文本小部件的中心在窗口的顶部,因此您看不到上半部分(包括插入的文本)。

To fix it use 要解决它使用

text.place(rely=0, relx=0.5, anchor='n')

to put the top of your text widget at the top of the window instead. 而是将文本小部件的顶部放在窗口顶部。

To avoid this kind of issue, you can use grid or pack instead of place . 为避免此类问题,可以使用gridpack代替place

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

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