import wx

app = wx.App()
win = wx.Frame(None)
win.Show()
app.MainLoop()

Why does the above code only work in python2.7 and not 3?

What do you mean do not work? What is the error message, what versions of wx you have installed in Python 2.7 and what in Python 3. Are you sure you switch between the versions properly (wxversion.select)?

Edited 4 Years Ago by pyTony

Thanks snippsat, I tested it out on my Windows machine:

'''wxp_combobox1.py
test the wx.ComboBox() widget
wx.ComboBox(parent, id, value, pos, size, choices, style)
a combination of a wx.TextCtrl() and a drop down listbox
tested with Python32 and wx(Phoenix)

downloaded
wxPython-Phoenix-r72945-win32-py3.2.tar.gz
from
http://wxpython.org/Phoenix/snapshot-builds/
then simply extracted the wx folder to
C:\Python32\Lib\site-packages
'''

import wx

class MyFrame(wx.Frame):
    def __init__(self, parent, mytitle, mysize):
        wx.Frame.__init__(self, parent, wx.ID_ANY, mytitle, size=mysize)
        self.SetBackgroundColour("yellow")

        choice_list = [str(year) for year in range(2000, 2015)]
        # create an input widget
        self.combo = wx.ComboBox( self, 200, choices=choice_list,
            pos=(10, 40), size=(150, 100))
        self.combo.SetValue('Select a year')
        # bind mouse click in the dropdown list to an action
        self.combo.Bind(wx.EVT_COMBOBOX, self.onAction)
        # the Enter key has been pressed in the entry field
        # this allows you to write/edit your own selection
        self.combo.Bind(wx.EVT_TEXT_ENTER, self.onAction)

        # create an output widget
        s = "Click on the right side drop down marker"
        self.label = wx.StaticText(self, wx.ID_ANY, s, pos=(10, 10))

    def onAction(self, event):
        """ some action code"""
        s = "You selected the year " + self.combo.GetValue()
        self.label.SetLabel(s)


app = wx.App(0)
# create a MyFrame instance and show the frame
MyFrame(None, 'testing wx.ComboBox()', (300, 200)).Show()
app.MainLoop()

As of 11/12/2012 not all the wx modules have been ported yet, for instance imageutils in wx.lib.buttons.

Edited 4 Years Ago by Lardmeister: date

This article has been dead for over six months. Start a new discussion instead.