wxpython - Wx.choice 在 ubuntu 中不工作

标签 wxpython

我只会说西类牙语,我会尽量用我糟糕的英语写,抱歉。

我正在学习 wx.Python,我在 Windows XP 中编写了一个小示例并运行完美,但相同的代码在 ubuntu Jaunty 中运行不佳。

wx.Choice的字体看起来很模糊,选项几乎看不到,当你选择一个时,Label总是空的。

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()

print self.choice1.Label 在 ubuntu 中总是打印 EMPTY,在 Windows 中打印 suma、resta 或 mul,wx.choice 的选项之一,如何预期。

里纳

最佳答案

使用self.choice1.Label是错误的;在整个代码中用 self.choice1.StringSelection 替换它,您的代码就可以工作了!

关于wxpython - Wx.choice 在 ubuntu 中不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/933177/

相关文章:

python - wxPython:wx.PyControl可以包含wx.Sizer吗?

python - wxPython多线程matplotlib绘图不在主线程中

python - WxPython 将选择转换为数值 TypeError

python - 如何获取wxPython中CreateButtonSizer(或CreateSeparatedButtonSizer)创建的按钮对象

python - 将文件对话框添加到菜单功能(打开)wxpython 3

python - 如何使用twisted来构建这个应用程序?

python - 以编程方式调用 wxPython EVT_BUTTON 事件

python - wxPython MacOS X Lion 全屏模式

python - 有没有一种简单的方法可以在 Python 或 wxPython 中捕获所有框架/窗口击键

python - Matplotlib 和 WxPython - Interactive Toolbar Plot 在点击时不进行刷新/更新