2009-06-01 8 views
3

저는 스페인어 만 사용합니다. 영어로 쓰려 고 노력합니다.우분투에서 Wx.choice가 작동하지 않습니다

나는 wx.Python을 배우고 있으며 Windows XP에서 작은 예제를 작성하고 완벽하게 실행하지만 우분투 Jaunty에서 같은 코드는 잘 작동하지 않습니다.

wx.Choice의 글꼴이 desfased로 표시되고 옵션이 거의 보이지 않습니다. 선택하면 레이블이 항상 비어 있습니다.

hxxp : //ricardonarvaja.info/WEB/OTROS/BOA%20CONSTRUCTOR%20PASO%20A%20PASO/instantanea1.png

enter code here 
#Boa:Frame:Frame1 

import wxversion 
wxversion.select('2.8') 
import wx 

print wx.version() 
def create(parent): 
    return Frame1(parent) 

[wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1CHOICE1, wxID_FRAME1PANEL1, 
wxID_FRAME1TEXTCTRL1, wxID_FRAME1TEXTCTRL2, 
] = [wx.NewId() for _init_ctrls in range(6)] 

class Frame1(wx.Frame): 
    def _init_sizers(self): 
     # generated method, don't edit 
     self.boxSizer1 = wx.BoxSizer(orient=wx.VERTICAL) 

    def _init_ctrls(self, prnt): 
     # generated method, don't edit 
     wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, 
       pos=wx.Point(473, 288), size=wx.Size(364, 190), 
       style=wx.DEFAULT_FRAME_STYLE, title='Frame1') 
     self.SetClientSize(wx.Size(356, 156)) 

     self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self, 
       pos=wx.Point(0, 0), size=wx.Size(356, 156), 
       style=wx.TAB_TRAVERSAL) 

     self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1', 
       parent=self.panel1, pos=wx.Point(40, 16), size=wx.Size(100, 21), 
       style=0, value=u'') 
     self.textCtrl1.Bind(wx.EVT_SET_FOCUS, self.OnTextCtrl1SetFocus) 

     self.textCtrl2 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL2, name='textCtrl2', 
       parent=self.panel1, pos=wx.Point(40, 48), size=wx.Size(100, 21), 
       style=0, value=u'') 
     self.textCtrl2.Bind(wx.EVT_SET_FOCUS, self.OnTextCtrl2SetFocus) 

     self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label=u'SUMAR', 
       name='button1', parent=self.panel1, pos=wx.Point(140, 101), 
       size=wx.Size(75, 23), style=0) 
     self.button1.Center(wx.HORIZONTAL) 
     self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button, 
       id=wxID_FRAME1BUTTON1) 

     self.choice1 = wx.Choice(choices=['suma', 'resta', 'mult'], 
       id=wxID_FRAME1CHOICE1, name='choice1', parent=self.panel1, 
       pos=wx.Point(160, 40), size=wx.Size(146, 21), style=0) 
     self.choice1.Bind(wx.EVT_CHOICE, self.OnChoice1Choice, 
       id=wxID_FRAME1CHOICE1) 

     self._init_sizers() 

    def __init__(self, parent): 
     self._init_ctrls(parent) 

    # XXX Este codigo esta sin terminar 
    def OnButton1Button(self, event): 

     print self.choice1.Label 
     try: 
      if self.choice1.Label=='suma': 
       suma=int(self.textCtrl1.Value)+int(self.textCtrl2.Value) 
       self.button1.Label='Suma = ' + str(suma) 
      if self.choice1.Label=='resta': 
       suma=int(self.textCtrl1.Value)- int(self.textCtrl2.Value) 
       self.button1.Label='Resta = ' + str(suma) 
      if self.choice1.Label=='mult': 
       suma=int(self.textCtrl1.Value) * int(self.textCtrl2.Value) 
       self.button1.Label='Mult = ' + str(suma) 
     except: 
      self.button1.Label='Error tipo de datos' 
      self.textCtrl1.Value='' 
      self.textCtrl2.Value='' 

     event.Skip() 

    def OnTextCtrl1SetFocus(self, event): 
     self.textCtrl1.Value='' 
     print self.choice1.Label 
     if self.choice1.Label=='suma': 
      self.button1.Label='SUMAR' 
     if self.choice1.Label=='resta': 
      self.button1.Label='RESTAR' 
     if self.choice1.Label=='mult': 
      self.button1.Label='MULT' 
     event.Skip() 

    def OnTextCtrl2SetFocus(self, event): 
     self.textCtrl2.Value='' 
     print self.choice1.Label 
     if self.choice1.Label=='suma': 
      self.button1.Label='SUMAR' 
     if self.choice1.Label=='resta': 
      self.button1.Label='RESTAR' 
     if self.choice1.Label=='mult': 
      self.button1.Label='MULT' 
     event.Skip() 

    def OnChoice1Choice(self, event): 

     if self.choice1.Label=='suma': 
      self.button1.Label='SUMAR' 
     if self.choice1.Label=='resta': 
      self.button1.Label='RESTAR' 
     if self.choice1.Label=='mult': 
      self.button1.Label='MULT' 

     event.Skip() 


if __name__ == '__main__': 
    app = wx.PySimpleApp() 
    frame = create(None) 
    frame.Show() 

    app.MainLoop() 

인쇄 self.choice1.Label 항상 우분투에서 EMPTY 인쇄 Windows에서는 wx.choice의 옵션 중 하나 인 suma, resta 또는 mul을 예상대로 인쇄합니다.

ricnar

+0

BTW에서는 일반적으로 wxPython 호출이 호출 될 때 점과 크기를 튜플로 바꿀 수 있습니다. –

답변

2

그것은 self.choice1.Label를 사용하는 것은 오류이다; 코드 전반에 걸쳐 self.choice1.StringSelection으로 바꾸면 코드가 작동합니다!

+0

하지만 Windows에서 레이블 작업, 호환성이 있다면, 우분투에서 작동해야합니다. ricnar –

+3

http://www.wxpython.org/docs/api/ & c에서 레이블이 "작동 중"(StringSelection과 동일하게)으로 문서화되어 있지 않습니다. Windows에서 우연히 작동하는 버그 일 수 있습니다. 또는 다른 버전 일 수도 있습니다 (2.8.4가 있습니다). 방금 설명한대로 설명서를 따라 코드를 수정하고 wx 사이트에서 버그를 열면 (저는 wx 개발자가 아니므로 사람들을 도우려고합니다). –

+0

감사합니다. 그리고 드물고 거의 보이지 않는 글꼴이있는 추악한 모양? StringSelection을 사용하면 windows가 나에게 올린 이미지와 비슷해 보입니다 ricnar –

관련 문제