为Python的Tkinter去除Text小部件的空边框
我在一个tkinter窗口里放了两个文本框。我的问题是,第二行的空白边框把第一行的一部分遮住了。
我查看了 http://effbot.org/tkinterbook/text.htm
,但所有默认的边框设置都是0。
这是我的代码,谢谢!
import Tkinter, tkFont, random
root=Tkinter.Tk()
root.geometry('+%d+%d' % (0,0)) #controls where the window is
root.geometry('%dx%d' % (600,350)) #controls window size
root.config(background="#fff")
firstLine = "First Line"
secondLine = "Second Line"
customFont = tkFont.Font(family="Agency FB",
size=100,
weight="bold")
text1 = Tkinter.Text(root,
font=customFont,
background="#fff",
fg="#000",
relief="flat")
text1.insert("end",firstLine)
text1.config(state='disabled')
text1.place(x=10,y=10) #controls where the text is placed
text2 = Tkinter.Text(root,
font=customFont,
background="#fff",
fg="#000",
relief="flat")
text2.insert("end",secondLine)
text2.config(state='disabled')
text2.place(x=10,y=125) #controls where the number is placed
root.mainloop()
1 个回答
1
我觉得这里有几个地方可能出错了。
首先,你说第二个框的边框在第一个框上面,但这其实不太准确。你看到的并不是边框,而是字体周围的空白区域。把边框或高亮厚度设置为零并不能解决这个问题,因为这是文本组件内部的空间。
其次,你可能误以为字体大小为100
就是100像素高。其实不是这样的,100
表示的是100个点的高度,而不是100个像素。如果你想要100像素高,可以设置为-100
。
第三,你使用了place
,这意味着你是在明确地把第二个组件放在第一个组件上面。我的猜测是,你把它放在y坐标125的位置,因为你认为第一个组件是100个组件高,但实际上并不是这样。
如果你想精确放置文本,可能应该使用画布和一些文本项目。组件并不是处理这个任务的最佳工具。