简体   繁体   English

在 Tkinter python 中设置条目文本框大小

[英]Setting entry text box size in Tkinter python

I am attempting to create a form that requires some entry options to be more than one line long.我正在尝试创建一个表单,该表单需要一些输入选项超过一行。 This does not seem possible with the .Entry() function.这对于 .Entry() 函数似乎是不可能的。

This issue is that I dont see anywhere in the documentation how to restrict the size of the text entry box (particularly, number of lines, or height)这个问题是我在文档中没有看到如何限制文本输入框的大小(特别是行数或高度)

To be clear, I am not trying to set the placement height, or text size, I am trying to restrict the number of lines where text can be entered (so the form is a predictable size) this is necessary because for each item I am using .place() to put them at certain pixel locations, and thus .pack() is not a viable solution for my problems either需要明确的是,我不是要设置放置高度或文本大小,而是要限制可以输入文本的行数(因此表单是可预测的大小)这是必要的,因为对于每个项目我都是使用 .place() 将它们放在某些像素位置,因此 .pack() 也不是解决我问题的可行方法

Some reference material:一些参考资料:

Documentation for entry widget条目小部件的文档

Use the text widget instead.改用文本小部件 It has a height option它有一个高度选项

Note: place requires integers that represent pixels, however, within the options of the text box, the width option requires integers that represent number of characters, and the height option requires an integer that represents number of lines.注意:place需要整数表示像素,但是在文本框的选项中,width选项需要整数表示字符数,height选项需要整数表示行数。 If you attempt to use height=20 expecting 20 pixels, you will be unpleasantly surprised.如果您尝试使用 height=20 期望 20 像素,您会感到不愉快的惊讶。 If you use width = 5, height = 5 it will not be square.如果您使用 width = 5, height = 5 它不会是正方形。

For reference, the default text size and font is an average of 8 pixels wide per character in the text widget, and 6 pixels per character in the default for the entry widget, so if you wanted a form to stretch a certain number of pixels, use width = round(pixel_length /6)作为参考,默认文本大小和字体是文本小部件中每个字符的平均宽度为 8 像素,输入小部件的默认值为每个字符 6 像素,因此如果您希望表单拉伸一定数量的像素,使用 width = round(pixel_length /6)

you can combine this with screen width and placement of the corner of forms to fill across the page or to near the end if you like您可以将其与屏幕宽度和表单角落的位置结合起来,以填充整个页面或接近末尾(如果您愿意)

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

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