[英]How to make text in a tkinter Entry widget stay to the right of the widget instead of the left?
[英]How to force tkinter text widget to stay on one line
我想創建一個類似於Label的對象,但我希望它也可以選擇進行復制粘貼。 我是使用Text小部件完成的:
class CopyLabel (Text):
def __init__ (self, master, text = '', font = None):
if font is None:
super().__init__(master = master, height = 1,
borderwidth = 0, width = len(text),
bg = master['background'])
else:
super().__init__(master = master, height = 1,
borderwidth = 0, font = font,
width = len(text), bg = master['background'])
self.insert(1.0, text)
self.configure(state = 'disabled')
我最終用網格顯示這個小部件。 但是,我隨機找到最后1或2個字符未顯示。 在研究這個時,似乎Text小部件將這些字符拆分為一個新行(選擇文本時,可以向下拖動以查看第二行)。 最大的問題是這種分裂的不可預測性(我嘗試做寬度= len(文本)+ 2,但我偶爾也會得到這種分裂行為)。 有沒有辦法糾正這種行為?
編輯:設置wrap ='none'修復了行拆分行為,但文本仍然被截斷。 現在我必須水平滾動而不是垂直滾動以查看文本,但我想這與我提出的問題不同。
您遇到的內容稱為換行 ,可以禁用修改Text小部件的wrap
選項,如下所示:
self['wrap'] = 'none'
要么
self.config(wrap='none')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.