2016-09-09 1 views
0

사용자 인터페이스 및 일부 텍스트 입력 작업은 기본 정보로 미리 채워집니다. 아래의 ScreenCap에서 보았 듯이 내가 미리 설정 한 텍스트는 TextCtrl의 왼쪽 가장자리 뒤에 강조 표시되어 숨겨져 있습니다. 이 문제를 어떻게 해결할 수 있습니까?wxPython TextCtrl에서 설정 한 텍스트가 왼쪽으로 미끄러 져 강조 표시되는 이유는 무엇입니까?

화면 캡 :

창 프레임 윈도우에 초점이 때 텍스트가 강조 표시됩니다. 내가 그것을 자르지 않은 것은 아니었다. fulle 텍스트는 "은/var/lib 디렉토리/CMT/바람둥이/CDES"

Image

(이미지 크기, 나는 SOF의 게시물 인터페이스의 크기를 조정하는 방법을 몰라 죄송합니다) 직접 relavent 코드 :

DirPath_O_Text = wx.StaticText(panel,label='Remote Directory Path', style=wx.ALIGN_RIGHT) 
    self.DirPath_O_TC = wx.TextCtrl(panel) 
    self.DirPath_O_TC.ChangeValue("/var/lib/cmt/tomcat/CDES") 

    hbox1.Add(DirPath_O_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
    hbox1.Add((25,-1)) 
    hbox1.Add(self.DirPath_O_TC, proportion=1,) 
    hbox1.Add((25,-1)) 

전체 코드 :

import wx 

class Popup(wx.Frame): 

    def __init__(self, *args, **kwargs): #initializing 
     super(Popup, self).__init__(*args, **kwargs) 

     self.SetMinSize((500,400)) #change this to change the minimum size of the total frame 
     self.Centre() 
     self.InitUI() 
     self.Show() 


    def InitUI(self): #building the UI 

     panel = wx.Panel(self) #main panel that holds everything 

     #setting font 
     font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT) 
     font.SetPointSize(16) #this is the size for the title, its smaller later on 

     #setting panel colour 
     # background_Colour = '#BCD7E0' 
     # panel.SetBackgroundColour(background_Colour) 

     ###########################  
     #vbox = sizer holds the whole thing 
     # Title = label 
     # hbox1 = sizer 
     #  Remote Directory Label 
     #  Remote Directory TextCtrl 
     # hbox2 = sizer 
     #  Local Directory Label 
     #  Local Directory TextCtrl 
     # hbox3 = sizer 
     #  Hostname Label 
     #  Hostname TextCtrl 
     # hbox4 = sizer 
     #  Username Label 
     #  Username TextCtrl 
     # hbox5 = sizer 
     #  Password Label 
     #  Password TextCtrl 
     # vbox2 = just used to align the hbox6 to center 
     #  hbox6 = sizer that holds the bottom two buttons 
     #  ok button = sends all info to next program 
     #  Cancel button = closes current program 

     ############### 
     #start 
     vbox = wx.BoxSizer(wx.VERTICAL) #oriented verticaly 

     ######### 
     #title  
     st_title = wx.StaticText(panel,label='CMT-CDES XML Messaging Tool', style=wx.ALIGN_CENTRE) 
     st_title.SetFont(font) 
     font.SetPointSize(9) #changes font back to small for all other text besides title 

     vbox.Add(st_title, proportion=1,flag=wx.EXPAND|wx.ALL, border=10) #adds the title 
     ###### 

     ######## 
     #6 sizers. 1-5 are for the inputs, 6 is for buttons on bottom 
     hbox1 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox2 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox3 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox4 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox5 = wx.BoxSizer(wx.HORIZONTAL) 
     hbox6 = wx.BoxSizer(wx.HORIZONTAL) 
     ######## 


     ######## 
     #set labels and TC for each hbox 

     #hbox1 
     DirPath_O_Text = wx.StaticText(panel,label='Remote Directory Path', style=wx.ALIGN_RIGHT) 
     self.DirPath_O_TC = wx.TextCtrl(panel) 
     self.DirPath_O_TC.ChangeValue("/var/lib/cmt/tomcat/CDES") 

     hbox1.Add(DirPath_O_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox1.Add((25,-1)) 
     hbox1.Add(self.DirPath_O_TC, proportion=1,) 
     hbox1.Add((25,-1)) 

     #hbox2 
     DirPath_L_Text = wx.StaticText(panel,label='Local Directory Path', style=wx.ALIGN_RIGHT) 
     self.DirPath_L_TC = wx.TextCtrl(panel) 

     hbox2.Add(DirPath_L_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox2.Add((25,-1)) 
     hbox2.Add(self.DirPath_L_TC, proportion=1,) 
     hbox2.Add((25,-1)) 

     #hbox3 
     Host_Text = wx.StaticText(panel,label='Hostname\IP', style=wx.ALIGN_RIGHT) 
     self.Host_TC = wx.TextCtrl(panel) 

     hbox3.Add(Host_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox3.Add((25,-1)) 
     hbox3.Add(self.Host_TC, proportion=1) 
     hbox3.Add((25,-1)) 

     #hbox4 
     User_Text = wx.StaticText(panel,label='Username', style=wx.ALIGN_RIGHT) 
     self.User_TC = wx.TextCtrl(panel) 

     hbox4.Add(User_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox4.Add((25,-1)) 
     hbox4.Add(self.User_TC, proportion=1) 
     hbox4.Add((25,-1)) 

     #hbox5 
     Pass_Text = wx.StaticText(panel,label='Password', style=wx.ALIGN_RIGHT) 
     self.Pass_TC = wx.TextCtrl(panel, style=wx.TE_PASSWORD) 

     hbox5.Add(Pass_Text, proportion=1,flag=wx.EXPAND|wx.BOTTOM,border=10) 
     hbox5.Add((25,-1)) 
     hbox5.Add(self.Pass_TC, proportion=1) 
     hbox5.Add((25,-1)) 
     ######## 

     ######## 
     #buttons 
     btn_size = (90, 30) 
     btn_OK = wx.Button(panel, label='OK', size=btn_size) 
     btn_Cancel = wx.Button(panel, label='Cancel', size=btn_size) 

     #bindings 
     btn_OK.Bind(wx.EVT_BUTTON, self.OK) #binds to ok (just takes variables from all text boxes, and passes to program) 
     btn_Cancel.Bind(wx.EVT_BUTTON, self.Cancel) #binds to cancel (just closes the window) 

     #holds buttons 
     hbox6.Add(btn_OK) 
     hbox6.Add((25,-1)) #spacer between buttons 
     hbox6.Add(btn_Cancel, flag=wx.ALIGN_RIGHT,proportion=0) 

     #aligns hbox 
     vbox2 = wx.BoxSizer(wx.VERTICAL) #added this vbox to set the alignment to center 
     vbox2.Add(hbox6, flag=wx.ALIGN_CENTRE, proportion = 0) 
     ####### 

     ############ 
     #add everything to main vbox 
     vbox.Add(hbox1,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     vbox.Add(hbox2,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     vbox.Add(hbox3,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     vbox.Add(hbox4,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     vbox.Add(hbox5,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 

     #buttons vbox 
     vbox.Add(vbox2,proportion=1,flag=wx.BOTTOM|wx.EXPAND, border=10) 
     ############ 

     #add main vbox to panel 
     panel.SetSizer(vbox) 

    def OK(self, e): 
     #creates a 5 item list, [DirPath_O, DirPath_L, Host, User, Pass] 
     args = [str(self.DirPath_O_TC.GetValue()) , str(self.DirPath_L_TC.GetValue()),str(self.Host_TC.GetValue()), str(self.User_TC.GetValue()), str(self.Pass_TC.GetValue())] 

     #print "args[1:5]: ", args 

     '''TODO 
     ''' 
     #call main, pass it args 
     #self.Close() #closes window when done 
     ''' 
     ''' 

     #TODO: Test if values are correct 

     print #not needed, just extra 

    def Cancel(self, e): #closes window 
     self.Close() 



#this is the main loop 
ex = wx.App() 
Popup(None) 
ex.MainLoop() 

답변

0

나는 텍스트가 기본적으로 정렬되어 있다고 믿습니다. 오른쪽 정렬을 원한다면 텍스트 컨트롤의 SetWindowStyle 메서드를 wx.TE_RIGHT 플래그와 함께 사용할 수 있다고 생각합니다.

이유는 첫 번째 텍스트 컨트롤이 텍스트를 강조 표시하는 이유는 첫 번째 텍스트 컨트롤이 포커스를받을 수있는 첫 번째 위젯이기 때문입니다. 포커스를 얻고 텍스트가 포함되어 있기 때문에 텍스트가 자동으로 강조 표시됩니다.

+0

왼쪽 정렬은 괜찮습니다. 걱정할 것은 텍스트의 절반이 왼쪽에서 잘리는 것입니다. 마치 프로그램에서 TextCtrl의 시작 부분이 표시되는 곳의 왼쪽이라고 생각하는 것처럼 말입니다. –

+0

'SetInsertionPoint (0)'호출 시도 –

+0

TextCtrl에서 호출하려고 시도했지만 불행하게도 아무런 차이가 없었습니다. –

관련 문제