import wx

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

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

Recommended Answers

All 4 Replies

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 (

According to
wxPython has not been ported to Python3 yet.

However, PySide/PyQT is available for all versions of Python.
Tkinter and its extensions tix and ttk are included in Python27 and all higher versions.

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

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)

then simply extracted the wx folder to

import wx

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

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.