...und hier die Komfortversion:
Code: Alles auswählen
#!/usr/bin/env python -O
# -*- coding: iso-8859-1 -*-
import wx
class MyDialog(wx.Dialog):
def __init__(
self, parent = None, id = -1, title = "Auswahl", message = "Bitte waehlen Sie aus"
):
wx.Dialog.__init__(self, parent, id, title)
border_box = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(border_box)
vbox = wx.BoxSizer(wx.VERTICAL)
border_box.Add(vbox, 1, wx.ALL | wx.EXPAND, 5)
lab = wx.StaticText(self, -1, message)
vbox.Add(lab, 0, wx.ALL, 10)
choices = ["erster", "zweiter"]
self.choices = choices
listbox = wx.ListBox(self, -1, choices = choices, size = (200, 100))
vbox.Add(listbox, 1, wx.ALL | wx.EXPAND, 5)
listbox.SetSelection(0)
self.listbox = listbox
border_box.Add(wx.StaticLine(self), 0, wx.EXPAND)
hbox = wx.BoxSizer(wx.HORIZONTAL)
border_box.Add(hbox, 0, wx.ALL | wx.EXPAND, 5)
cmd_cancel = wx.Button(self, wx.ID_CANCEL, "Abbrechen")
hbox.Add(cmd_cancel, 0, wx.ALL, 5)
hbox.Add((0, 0), 1)
cmd_ok = wx.Button(self, wx.ID_OK, "OK")
hbox.Add(cmd_ok, 0, wx.ALL, 5)
self.Fit()
def get_selection(self):
listbox = self.listbox
choices = self.choices
return choices[listbox.GetSelection()]
def main():
app = wx.PySimpleApp()
diag = MyDialog()
if diag.ShowModal() == wx.ID_OK:
print diag.get_selection()
else:
print "Abbruch"
if __name__ == "__main__":
main()
mfg
Gerold
