Listbox problem

Hey all. I’m trying to write a simple application, to calculate the odds for poker. However, I have run into a problem.

The
idea is that the user selects both cards he/she has, use a checkbox to
set if they are suited or not, and finally, press Calculate.

The
strange thing however is that I can’t select anything in either of the
boxes!! The checkmark works fine, but the boxes just won’t work
correctly. Can anyone help me out?

         Pure Box Script

    self.box1 = wx.ListBox(parent=self, id=

wx.ID_ANY, size=(60,163) , name=‘Card 1’,
choices=[‘Ace’,‘King’,‘Queen’,‘Ten’,‘9’,‘8’,‘7’,‘6’,‘5’,‘4’,‘3’,‘2’],style=0)

    self.box2 = wx.ListBox(parent=self, id=wx.ID_ANY, size=(60,163) , name='Card 2',
                           choices=['Ace','King','Queen','Ten','9','8','7','6','5','4','3','2'],style=0)
    self.box1.Bind(wx.EVT_LISTBOX, self.b1func,id=self.box1.GetId())
    self.box2.Bind(wx.EVT_LISTBOX, self.b2func

,id=self.box2.GetId())

    self.sizer.Add( self.box1   , ( 1 , 0 ) )
    self.sizer.Add( self.box2   , ( 1 , 1 ) )

          Full Script

mport wx
ID_BUTTON = 100
ID_ABOUT=110
ID_EXIT=200
class MainWindow(
wx.Frame):
“”" We simply derive a new class of Frame. “”"
def init(self,parent,id, title):
#Setup Frame, Panel and Sizer
wx.Frame.init(self,parent,
wx.ID_ANY,title,size=(150,305))
self.panel = wx.Panel ( self, -1 )
self.sizer = wx.GridBagSizer ( 7, 5 )
#Setup File menu
self.CreateStatusBar()
filemenu= wx.Menu()

    filemenu.Append(ID_ABOUT, "&About"," About this program")
    filemenu.AppendSeparator()
    filemenu.Append(ID_EXIT,"E&xit"," Terminate the program")

    menuBar = wx.MenuBar()
    menuBar.Append(filemenu,"&File")
    self.SetMenuBar(menuBar)
    wx.EVT_MENU(self, ID_ABOUT, self.OnAbout)
    wx.EVT_MENU(self, ID_EXIT, self.OnExit

)
#Just a little banner, explaining what to do
self.label = wx.StaticText ( self.panel, -1, “Select your cards.\nDon’t forget to set if\nthey are suited or not!”, style = wx.TE_CENTER )

    #Boxes, to select cards
    self.box1 = wx.ListBox(parent=self, id=wx.ID_ANY, size=(60,163) , name='Card 1',
                           choices=['Ace','King','Queen','Ten','9','8','7','6','5','4','3','2'],style=0)

    self.box2 = wx.ListBox(parent=self, id=wx.ID_ANY, size=(60,163) , name='Card 2',
                           choices=['Ace','King','Queen','Ten','9','8','7','6','5','4','3','2'],style=0)
    self.box1.Bind

(wx.EVT_LISTBOX, self.b1func,id=self.box1.GetId())
self.box2.Bind(wx.EVT_LISTBOX, self.b2func,id=self.box2.GetId())
#Checkbox, suited or unsuited
self.suited = wx.CheckBox ( self.panel, -1, " Suited ")

    #Finally, a button to start the calculations
    self.button = wx.Button ( self.panel, ID_BUTTON, " Calculate " )
    wx.EVT_BUTTON ( self.panel, ID_BUTTON, self.Calculate )
    #Add everything to the sizer, so that it is showed in a orderly fashion

    self.sizer.Add( self.label   , ( 0 , 0 ) , ( 1 ,  2) , wx.ALIGN_CENTER  )
    self.sizer.Add( self.box1   , ( 1 , 0 ) )
    self.sizer.Add( self.box2   , ( 1 , 1 ) )
     self.sizer.Add( self.suited

, ( 2 , 0 ) )
self.sizer.Add( self.button , ( 2 , 1 ) )
# Center everything, and attach sizer to panel
self.horizontal = wx.BoxSizer ( wx.HORIZONTAL )
self.horizontal.Add ( ( 0, 0 ), 1 )

    self.horizontal.Add ( self.sizer )
    self.horizontal.Add ( ( 0, 0 ), 1 )
    self.vertical = wx.BoxSizer ( wx.VERTICAL )
    self.vertical.Add ( ( 0, 0, ), 1 )
     self.vertical.Add

( self.horizontal, 0, wx.ALIGN_CENTER )
self.vertical.Add ( ( 0, 0 ), 1 )
self.panel.SetSizerAndFit ( self.vertical )
#Show it all, you nasty bitch
self.Show(True)

DONE: making c1str highest card

def Calculate (self,e):
    #Getting user input
    c1str = self.box1.GetSelection()
    c2str = self.box2.GetSelection()
    suit = self.suited.GetValue()
    if c1str == -1 or c2str == -1:

        print "!ERROR!\nSelect your cards first."
    else:
        #Debug
        print str(c1str) + " " + str(c2str)
        print str(suit)
        if c1str == "Ace":

            c1int = 14
        elif c1str == "King":
            c1int = 13
        elif c1str == "Queen":
            c1int = 12
        elif c1str == "Jack":

            c1int = 11
        elif c1str == "Ten":
            c1int = 10
        else:
            c1int = int(c1str)
        if c2str == "Ace":
            c2int = 14

        elif c2str == "King":
            c2int = 13
        elif c2str == "Queen":
            c2int = 12
        elif c2str == "Jack":
            c2int = 11

        elif c2str == "Ten":
            c2int = 10
        else:
            c2int = int(c2str)

if

def b1func (self,e):
    print self.box1.GetSelection

()

def b2func (self,e):
    print self.box2.GetSelection()
   
def OnAbout (self,e):
    #Simple about message TODO add site url
    d= wx.MessageDialog( self, " DisAstro's Texas Hold 'Em Calculator.\n"

                         "A Texas Hold Em Preflop Calculator\n"
                         "\n"
                         "Made by DisAstro.\n"

“INSERT SITE HERE\n”

                         "\n"
                         "Copyright 2006 'The Balhaar Clan.'\n"
                         "All rights reserved"," About DA THC ", wx.OK)
    d.ShowModal()
    d.Destroy()

def OnExit(self,e):
    #Close the frame.
    self.Close(True)

app = wx.PySimpleApp()
frame=MainWindow(None,-1,‘DA THC’)
app.MainLoop
()

Thanks in advance to anyone trying to help me!

Toon Pieton wrote:

Hey all. I'm trying to write a simple application, to calculate the odds for poker. However, I have run into a problem.

The idea is that the user selects both cards he/she has, use a checkbox to set if they are suited or not, and finally, press Calculate.

The strange thing however is that I can't select anything in either of the boxes!! The checkmark works fine, but the boxes just won't work correctly. Can anyone help me out?

             Pure Box Script

...

       self.box1 = wx.ListBox(parent=self, id= wx.ID_ANY, size=(60,163) , name='Card 1',
                               choices=['Ace','King','Queen','Ten','9','8','7','6','5','4','3','2'],style=0)

        self.box2 = wx.ListBox(parent=self, id=wx.ID_ANY, size=(60,163) , name='Card 2',
                               choices=['Ace','King','Queen','Ten','9','8','7','6','5','4','3','2'],style=0)
        self.box1.Bind(wx.EVT_LISTBOX, self.b1func,id=self.box1.GetId())
        self.box2.Bind(wx.EVT_LISTBOX, self.b2func ,id=self.box2.GetId())

Make the parent be self.sizer.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!