python - Tix ComboBox causes python2.7 to crash -


i've been using tix create combobox , causes intermittent crash if entry box left empty.

i'm new python , new gui programming i've been using example teach myself stuff.

when using following example code, should able enter value entry box or select form dropdown menu, if leave entry field empty , press go cause python crash.

import tix import tkmessagebox  class app(object):     def __init__(self, window):         window.winfo_toplevel().wm_title("test")         self.window = window          self.combo = tix.combobox(window)         self.combo.insert(tix.end, 'thing1')         self.combo.insert(tix.end, 'thing2')         self.combo.entry['state'] = "normal"         self.combo['editable'] = true         self.combo.pack()          button = tix.button(window)         button['text'] = "go"         button['command'] = self.go         button.pack()      def go(self):         tkmessagebox.showinfo('info', self.combo['selection'])  if __name__ == '__main__':     root = tix.tk()     app(root)     root.mainloop() 

========================= crash details :

  problem signature:   problem event name:   appcrash   application name: python2.7.exe   application version:  0.0.0.0   application timestamp:    4cfbf049   fault module name:    ntdll.dll   fault module version: 6.1.7600.16385   fault module timestamp:   4a5bdb3b   exception code:   c0000005   exception offset: 0002e23e   os version:   6.1.7600.2.0.0.256.48   locale id:    2057   additional information 1: 0a9e   additional information 2: 0a9e372d3b4ad19135b953a78882e789   additional information 3: 0a9e   additional information 4: 0a9e372d3b4ad19135b953a78882e789 

so

a] example doing wrong ?

b] there better way?

c] should using tix @ ?

i've noticed people seem shy away tix , use tkinter. there reason this? should not using tix ?

++++++++++++++++++++++++++++

ok managed monkeypatch adding value =' ' return string not empty , lstrip() value when need it.

self.combo = tix.combobox(window, value =' ') ... tkmessagebox.showinfo('info', self.combo['selection'].lstrip()) 

very ugly stops me crashing now; until wiser can give me better answer. if user deletes space , presses 'go' of cause crash again!

i not tix expert, should fix problem:

tkmessagebox.showinfo('info', self.combo.entry.get()) 

in between lines, recommend using wxpython learning gui programming. great me learning environment.

import wx  class mainwin(wx.frame):     def __init__(self, *args, **kwargs):         wx.frame.__init__(self, *args, **kwargs)          self.combo = wx.combobox(self, choices=["thing 1", "thing 2"])               self.button = wx.button(self, label="go")         self.button.bind(wx.evt_button, self.onbutton)          self.sizer = wx.boxsizer(wx.vertical)         self.sizer.add(self.combo, 0, wx.expand)         self.sizer.add(self.button, 0, wx.expand)         self.setsizerandfit(self.sizer)               self.show()      def onbutton(self, e):         wx.messagebox(self.combo.getvalue())  app = wx.app(false) main_win = mainwin(none) app.mainloop() 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -