set text alignment of rich text ctrl

浪尽此生 提交于 2020-01-17 03:05:38

问题


how to align text right and center because wx.TE_RIGHT and wx.TE_CENTER is not working in the code below

 import wx
 import wx.richtext as rtc
 class test(wx.Dialog): 
    def __init__(self, *args, **kwds): 
       wx.Dialog.__init__(self, *args, **kwds) 
       self.V=rtc.RichTextCtrl(self, size=(400,90),style=wx.TE_RIGHT|rtc.RE_MULTILINE)
 if __name__ == '__main__': 
  app = wx.App() 
  dialog = test(None, -1) 

  dialog.Show() 
  app.MainLoop() 

回答1:


Instead of trying to apply both styles I moved the center styling to a new line of code using ApplyAlignmentToSelction() from this documentation. http://xoomer.virgilio.it/infinity77/wxPython/richtext/wx.richtext.RichTextAttr.html

import wx
import wx.richtext as rtc
class test(wx.Dialog):
    def __init__(self, *args, **kwds): 
        wx.Dialog.__init__(self, *args, **kwds) 
        self.V=rtc.RichTextCtrl(self, size=(400,90),style=rtc.RE_MULTILINE)
        self.V.ApplyAlignmentToSelection(rtc.TEXT_ALIGNMENT_CENTER)

if __name__ == '__main__': 
    app = wx.App() 
    dialog = test(None, -1) 
    dialog.Show() 
    app.MainLoop() 


来源:https://stackoverflow.com/questions/27767612/set-text-alignment-of-rich-text-ctrl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!